# lib/psm.c File Reference

Package state machine to handle a package from a transaction set. More...

`#include "system.h"`
`#include "psm.h"`
`#include <rpmmacro.h>`
`#include <rpmurl.h>`
`#include "depends.h"`
`#include "rpmlead.h"`
`#include "signature.h"`
`#include "ugid.h"`
`#include "misc.h"`
`#include "rpmdb.h"`
`#include "debug.h"`

Go to the source code of this file.

## Data Structures

struct | tagMacro
| Macros to be defined from per-header tag values. More...

## Functions

int | rpmVersionCompare (Header first, Header second)
| Compare headers to determine which header is "newer".
void | loadFi (Header h, TFI_t fi)
| Load data from header into transaction file element info.
void | freeFi (TFI_t fi)
| Destroy transaction element file info.
const char *const | fiTypeString (TFI_t fi)
| Return formatted string representation of package disposition.
static int | rpmInstallLoadMacros (TFI_t fi, Header h)
| Define per-header macros.
static int | mergeFiles (TFI_t fi, Header h, Header newH)
| Copy file data from h to newH.
static int | markReplacedFiles (PSM_t psm)
| Mark files in database shared with this package as "replaced".
static rpmRC | chkdir (const char *dpath, const char *dname)
| Create directory if it does not exist, make sure path is writable.
rpmRC | rpmInstallSourcePackage (const char *rootDir, FD_t fd, const char **specFilePtr, rpmCallbackFunction notify, rpmCallbackData notifyData, char **cookie)
| Install source package.
static const char *const | tag2sln (int tag)
| Return scriptlet name from tag.
static int | runScript (PSM_t psm, Header h, const char *sln, int progArgc, const char **progArgv, const char *script, int arg1, int arg2)
| Run scriptlet with args.
static rpmRC | runInstScript (PSM_t psm)
| Retrieve and run scriptlet from header.
static int | handleOneTrigger (PSM_t psm, Header sourceH, Header triggeredH, int arg2, unsigned char *triggersAlreadyRun)
static int | runTriggers (PSM_t psm)
| Run trigger scripts in the database that are fired by this header.
static int | runImmedTriggers (PSM_t psm)
| Run triggers from this header that are fired by headers in the database.
static const char *const | pkgStageString (pkgStage a)
int | psmStage (PSM_t psm, pkgStage stage)
| Package state machine driver.

## Variables

static struct tagMacro | tagMacros []
| Macros to be defined from per-header tag values.
static char * | SCRIPT_PATH

## Detailed Description

Package state machine to handle a package from a transaction set.

Definition in file psm.c.

## Function Documentation

static rpmRC chkdir | ( | const char * | dpath,
|  | const char * | dname |
| ) |  |  | `[static]`

Create directory if it does not exist, make sure path is writable.

Note:
  This will only create last component of directory path.

Parameters:

  | dpath | directory path
  | dname | directory use

Returns:
  rpmRC return code

Definition at line 577 of file psm.c.

const char* const fiTypeString | ( | TFI_t | fi | ) |

Return formatted string representation of package disposition.

Parameters:

  | a | package dispostion

Returns:
  formatted string

Definition at line 235 of file psm.c.

void freeFi | ( | TFI_t | fi | ) |

Destroy transaction element file info.

Parameters:

  | fi | transaction element file info

Definition at line 188 of file psm.c.

static int handleOneTrigger | ( | PSM_t | psm,
|  | Header | sourceH,
|  | Header | triggeredH,
|  | int | arg2,
|  | unsigned char * | triggersAlreadyRun |
| ) |  |  | `[static]`

Parameters:

  | psm | package state machine data
  | sourceH |
  | triggeredH |
  | arg2 |
  | triggersAlreadyRun |

Returns:

Definition at line 1093 of file psm.c.

void loadFi | ( | Header | h,
|  | TFI_t | fi |
| ) |  |  |

Load data from header into transaction file element info.

Parameters:

  | h | header
  | fi | transaction element file info

Definition at line 72 of file psm.c.

static int markReplacedFiles | ( | PSM_t | psm | ) | `[static]`

Mark files in database shared with this package as "replaced".

Parameters:

  | psm | package state machine data

Returns:
  0 always

Definition at line 497 of file psm.c.

static int mergeFiles | ( | TFI_t | fi,
|  | Header | h,
|  | Header | newH |
| ) |  |  | `[static]`

Copy file data from h to newH.

Parameters:

  | h | header from
  | newH | header to
  | actions | array of file dispositions

Returns:
  0 on success, 1 on failure

Definition at line 314 of file psm.c.

static const char* const pkgStageString | ( | pkgStage | a | ) | `[static]`

Definition at line 1298 of file psm.c.

int psmStage | ( | PSM_t | psm,
|  | pkgStage | stage |
| ) |  |  |

Package state machine driver.

Todo:
  Packages w/o files never get a callback, hence don't get displayed on install with -v.

Definition at line 1342 of file psm.c.

static int rpmInstallLoadMacros | ( | TFI_t | fi,
|  | Header | h |
| ) |  |  | `[static]`

Define per-header macros.

Parameters:

  | fi | transaction element file info
  | h | header

Returns:
  0 always

Definition at line 267 of file psm.c.

rpmRC rpmInstallSourcePackage | ( | const char * | rootDir,
|  | FD_t | fd,
|  | const char ** | specFilePtr,
|  | rpmCallbackFunction | notify,
|  | rpmCallbackData | notifyData,
|  | char ** | cookie |
| ) |  |  |

Install source package.

Parameters:

  | rootDir | path to top of install tree (or NULL)
  | fd | file handle

Return values:

  | specFilePtr | address of spec file name (or NULL)

Parameters:

  | notify | progress callback
  | notifyData | progress callback private data

Return values:

  | cooke | address of cookie pointer (or NULL)

Returns:
  rpmRC return code

Definition at line 612 of file psm.c.

int rpmVersionCompare | ( | Header | first,
|  | Header | second |
| ) |  |  |

Compare headers to determine which header is "newer".

Parameters:

  | first | 1st header
  | second | 2nd header

Returns:
  result of comparison

Definition at line 36 of file psm.c.

static int runImmedTriggers | ( | PSM_t | psm | ) | `[static]`

Run triggers from this header that are fired by headers in the database.

Parameters:

  | psm | package state machine data

Returns:
  0 on success, 1 on error

Definition at line 1246 of file psm.c.

static rpmRC runInstScript | ( | PSM_t | psm | ) | `[static]`

Retrieve and run scriptlet from header.

Parameters:

  | psm | package state machine data

Returns:
  rpmRC return code

Definition at line 1046 of file psm.c.

static int runScript | ( | PSM_t | psm,
|  | Header | h,
|  | const char * | sln,
|  | int | progArgc,
|  | const char ** | progArgv,
|  | const char * | script,
|  | int | arg1,
|  | int | arg2 |
| ) |  |  | `[static]`

Run scriptlet with args.

Run a script with an interpreter. If the interpreter is not specified, /bin/sh will be used. If the interpreter is /bin/sh, then the args from the header will be ignored, passing instead arg1 and arg2.

Parameters:

  | psm | package state machine data
  | h | header
  | sln | name of scriptlet section
  | progArgc | no. of args from header
  | progArgv | args from header, progArgv[0] is the interpreter to use
  | script | scriptlet from header
  | arg1 | no. instances of package installed after scriptlet exec (-1 is no arg)
  | arg2 | ditto, but for the target package

Returns:
  0 on success, 1 on error

Definition at line 825 of file psm.c.

static int runTriggers | ( | PSM_t | psm | ) | `[static]`

Run trigger scripts in the database that are fired by this header.

Parameters:

  | psm | package state machine data

Returns:
  0 on success, 1 on error

Definition at line 1209 of file psm.c.

static const char* const tag2sln | ( | int | tag | ) | `[static]`

Return scriptlet name from tag.

Parameters:

  | tag | scriptlet tag

Returns:
  name of scriptlet

Definition at line 794 of file psm.c.

## Variable Documentation

char* SCRIPT_PATH `[static]`

Initial value:

            "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin"

Definition at line 786 of file psm.c.

struct tagMacro tagMacros[]`[static]`

Macros to be defined from per-header tag values.

Todo:
  Should other macros be added from header when installing a package?