Skip to content

Commit

Permalink
Add --filetriggers option to show info about file triggers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lubos Kardos committed Aug 6, 2015
1 parent c16c70c commit d18fdd7
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 10 deletions.
4 changes: 4 additions & 0 deletions lib/rpmtag.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ typedef enum rpmTag_e {
RPMTAG_REMOVEPATHPOSTFIXES = 5083, /* s internal */
RPMTAG_FILETRIGGERPRIORITIES = 5084, /* i[] */
RPMTAG_TRANSFILETRIGGERPRIORITIES = 5085, /* i[] */
RPMTAG_FILETRIGGERCONDS = 5086, /* s[] extension */
RPMTAG_FILETRIGGERTYPE = 5087, /* s[] extension */
RPMTAG_TRANSFILETRIGGERCONDS = 5088, /* s[] extension */
RPMTAG_TRANSFILETRIGGERTYPE = 5089, /* s[] extension */

RPMTAG_FIRSTFREE_TAG /*!< internal */
} rpmTag;
Expand Down
107 changes: 97 additions & 10 deletions lib/tagexts.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,62 @@ static int filedepTag(Header h, rpmTag tagN, rpmtd td, headerGetFlags hgflags)
return rc;
}

typedef enum tMode_e {
NORMALTRIGGER = 0,
FILETRIGGER = 1,
TRANSFILETRIGGER = 2,
} tMode;

/**
* Retrieve trigger info.
* @param h header
* @retval td tag data container
* @param hgflags header get flags
* @return 1 on success
*/
static int triggercondsTag(Header h, rpmtd td, headerGetFlags hgflags)
static int triggercondsTagFor(tMode mode, Header h, rpmtd td,
headerGetFlags hgflags)
{
uint32_t * indices;
int i, j;
char ** conds;
struct rpmtd_s nametd, indextd, flagtd, versiontd, scripttd;
int hgeflags = HEADERGET_MINMEM;
rpmTagVal triggername, triggerindex, triggerflags;
rpmTagVal triggerversion, triggerscripts;

switch (mode) {
case NORMALTRIGGER:
triggername = RPMTAG_TRIGGERNAME;
triggerindex = RPMTAG_TRIGGERINDEX;
triggerflags = RPMTAG_TRIGGERFLAGS;
triggerversion = RPMTAG_TRIGGERVERSION;
triggerscripts = RPMTAG_TRIGGERSCRIPTS;
break;
case FILETRIGGER:
triggername = RPMTAG_FILETRIGGERNAME;
triggerindex = RPMTAG_FILETRIGGERINDEX;
triggerflags = RPMTAG_FILETRIGGERFLAGS;
triggerversion = RPMTAG_FILETRIGGERVERSION;
triggerscripts = RPMTAG_FILETRIGGERSCRIPTS;
break;
case TRANSFILETRIGGER:
triggername = RPMTAG_TRANSFILETRIGGERNAME;
triggerindex = RPMTAG_TRANSFILETRIGGERINDEX;
triggerflags = RPMTAG_TRANSFILETRIGGERFLAGS;
triggerversion = RPMTAG_TRANSFILETRIGGERVERSION;
triggerscripts = RPMTAG_TRANSFILETRIGGERSCRIPTS;
break;
}

if (!headerGet(h, RPMTAG_TRIGGERNAME, &nametd, hgeflags)) {
if (!headerGet(h, triggername, &nametd, hgeflags)) {
return 0;
}

headerGet(h, RPMTAG_TRIGGERINDEX, &indextd, hgeflags);
headerGet(h, RPMTAG_TRIGGERFLAGS, &flagtd, hgeflags);
headerGet(h, RPMTAG_TRIGGERVERSION, &versiontd, hgeflags);
headerGet(h, RPMTAG_TRIGGERSCRIPTS, &scripttd, hgeflags);
headerGet(h, triggerindex, &indextd, hgeflags);
headerGet(h, triggerflags, &flagtd, hgeflags);
headerGet(h, triggerversion, &versiontd, hgeflags);
headerGet(h, triggerscripts, &scripttd, hgeflags);

td->type = RPM_STRING_ARRAY_TYPE;
td->flags = RPMTD_ALLOCED | RPMTD_PTR_ALLOCED;
Expand Down Expand Up @@ -262,25 +295,60 @@ static int triggercondsTag(Header h, rpmtd td, headerGetFlags hgflags)
return 1;
}

static int triggercondsTag(Header h, rpmtd td, headerGetFlags hgflags)
{
return triggercondsTagFor(NORMALTRIGGER, h, td, hgflags);
}

static int filetriggercondsTag(Header h, rpmtd td, headerGetFlags hgflags)
{
return triggercondsTagFor(FILETRIGGER, h, td, hgflags);
}

static int transfiletriggercondsTag(Header h, rpmtd td, headerGetFlags hgflags)
{
return triggercondsTagFor(TRANSFILETRIGGER, h, td, hgflags);
}

/**
* Retrieve trigger type info.
* @param h header
* @retval td tag data container
* @param hgflags header get flags
* @return 1 on success
*/
static int triggertypeTag(Header h, rpmtd td, headerGetFlags hgflags)
static int triggertypeTagFor(tMode mode, Header h, rpmtd td,
headerGetFlags hgflags)
{
int i;
char ** conds;
struct rpmtd_s indices, flags, scripts;
rpmTagVal triggerindex, triggerflags, triggerscripts;

switch (mode) {
case NORMALTRIGGER:
triggerindex = RPMTAG_TRIGGERINDEX;
triggerflags = RPMTAG_TRIGGERFLAGS;
triggerscripts = RPMTAG_TRIGGERSCRIPTS;
break;
case FILETRIGGER:
triggerindex = RPMTAG_FILETRIGGERINDEX;
triggerflags = RPMTAG_FILETRIGGERFLAGS;
triggerscripts = RPMTAG_FILETRIGGERSCRIPTS;
break;
case TRANSFILETRIGGER:
triggerindex = RPMTAG_TRANSFILETRIGGERINDEX;
triggerflags = RPMTAG_TRANSFILETRIGGERFLAGS;
triggerscripts = RPMTAG_TRANSFILETRIGGERSCRIPTS;
break;
}

if (!headerGet(h, RPMTAG_TRIGGERINDEX, &indices, HEADERGET_MINMEM)) {
if (!headerGet(h, triggerindex, &indices, HEADERGET_MINMEM)) {
return 0;
}

headerGet(h, RPMTAG_TRIGGERFLAGS, &flags, HEADERGET_MINMEM);
headerGet(h, RPMTAG_TRIGGERSCRIPTS, &scripts, HEADERGET_MINMEM);
headerGet(h, triggerflags, &flags, HEADERGET_MINMEM);
headerGet(h, triggerscripts, &scripts, HEADERGET_MINMEM);

td->flags = RPMTD_ALLOCED | RPMTD_PTR_ALLOCED;
td->count = rpmtdCount(&scripts);
Expand Down Expand Up @@ -316,6 +384,21 @@ static int triggertypeTag(Header h, rpmtd td, headerGetFlags hgflags)
return 1;
}

static int triggertypeTag(Header h, rpmtd td, headerGetFlags hgflags)
{
return triggertypeTagFor(NORMALTRIGGER, h, td, hgflags);
}

static int filetriggertypeTag(Header h, rpmtd td, headerGetFlags hgflags)
{
return triggertypeTagFor(FILETRIGGER, h, td, hgflags);
}

static int transfiletriggertypeTag(Header h, rpmtd td, headerGetFlags hgflags)
{
return triggertypeTagFor(TRANSFILETRIGGER, h, td, hgflags);
}

/**
* Retrieve installed file paths.
* @param h header
Expand Down Expand Up @@ -873,7 +956,11 @@ static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
{ RPMTAG_FILEPROVIDE, fileprovideTag },
{ RPMTAG_FILEREQUIRE, filerequireTag },
{ RPMTAG_TRIGGERCONDS, triggercondsTag },
{ RPMTAG_FILETRIGGERCONDS, filetriggercondsTag },
{ RPMTAG_TRANSFILETRIGGERCONDS, transfiletriggercondsTag },
{ RPMTAG_TRIGGERTYPE, triggertypeTag },
{ RPMTAG_FILETRIGGERTYPE, filetriggertypeTag },
{ RPMTAG_TRANSFILETRIGGERTYPE, transfiletriggertypeTag },
{ RPMTAG_LONGFILESIZES, longfilesizesTag },
{ RPMTAG_LONGARCHIVESIZE, longarchivesizeTag },
{ RPMTAG_LONGSIZE, longsizeTag },
Expand Down
8 changes: 8 additions & 0 deletions rpmpopt.in
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ rpm alias --triggerscripts --qf '\
rpm alias --triggers --triggerscripts \
--POPTdesc=$"list trigger scriptlets from package(s)"

rpm alias --filetriggerscripts --qf '\
[filetrigger%{FILETRIGGERTYPE} scriptlet (using %{FILETRIGGERSCRIPTPROG}) -- \
%{FILETRIGGERCONDS}\n%{FILETRIGGERSCRIPTS}\n]\
[transfiletrigger%{TRANSFILETRIGGERTYPE} scriptlet (using %{TRANSFILETRIGGERSCRIPTPROG}) -- \
%{TRANSFILETRIGGERCONDS}\n%{TRANSFILETRIGGERSCRIPTS}\n]'
rpm alias --filetriggers --filetriggerscripts \
--POPTdesc=$"list filetrigger scriptlets from package(s)"

rpm alias --last --qf '%|INSTALLTIME?{%{INSTALLTIME}}:{000000000}| %{NVRA} %|INSTALLTIME?{%{INSTALLTIME:date}}:{(not installed)}|\n' \
--pipe "LC_NUMERIC=C sort -r -n | sed 's,^[0-9]\+ ,,' | awk '{printf(\"%-45s %-s\n\", $1, substr($0,length($1)+2))}' " \
--POPTdesc=$"list package(s) by install time, most recent first"
Expand Down
4 changes: 4 additions & 0 deletions tests/rpmgeneral.at
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ FILERDEVS
FILEREQUIRE
FILESIZES
FILESTATES
FILETRIGGERCONDS
FILETRIGGERFLAGS
FILETRIGGERINDEX
FILETRIGGERNAME
FILETRIGGERPRIORITIES
FILETRIGGERSCRIPTFLAGS
FILETRIGGERSCRIPTPROG
FILETRIGGERSCRIPTS
FILETRIGGERTYPE
FILETRIGGERVERSION
FILEUSERNAME
FILEVERIFYFLAGS
Expand Down Expand Up @@ -256,13 +258,15 @@ SUPPLEMENTNAME
SUPPLEMENTNEVRS
SUPPLEMENTS
SUPPLEMENTVERSION
TRANSFILETRIGGERCONDS
TRANSFILETRIGGERFLAGS
TRANSFILETRIGGERINDEX
TRANSFILETRIGGERNAME
TRANSFILETRIGGERPRIORITIES
TRANSFILETRIGGERSCRIPTFLAGS
TRANSFILETRIGGERSCRIPTPROG
TRANSFILETRIGGERSCRIPTS
TRANSFILETRIGGERTYPE
TRANSFILETRIGGERVERSION
TRIGGERCONDS
TRIGGERFLAGS
Expand Down

0 comments on commit d18fdd7

Please sign in to comment.