Implement include-filtering for verification too

Since it comes at very nearly zero cost now, support include-filtering
(--configfiles etc) for verify too.

The actual functionality is little more than a single if-continue
in the verify code, what unfortunately makes this commit so "big" is
rearranging the popt tables to have separate file selection options
table that is common for both query and verify, plus update the
manual to reflect that, plus testcases for the functionality.
This commit is contained in:
Panu Matilainen 2017-11-10 12:42:59 +02:00
parent 0636ce28aa
commit e197625cd1
6 changed files with 79 additions and 59 deletions

View File

@ -526,8 +526,8 @@ two columns, you could use \fB%-30{NAME}%{DISTRIBUTION}\fR.
\fBrpm\fR will print a list of all of the tags it knows about when it
is invoked with the \fB--querytags\fR argument.
.PP
There are two subsets of options for querying: package selection,
and information selection.
There are three subsets of options for querying: package selection,
file selection and information selection.
.SS "PACKAGE SELECTION OPTIONS:"
.PP
.TP
@ -632,24 +632,15 @@ Query all packages that enhance \fICAPABILITY\fR.
.SS "PACKAGE QUERY OPTIONS:"
.PP
.TP
\fB-d, --artifactfiles\fR
List only artifact files (implies \fB-l\fR).
.TP
\fB--changelog\fR
Display change information for the package.
.TP
\fB--changes\fR
Display change information for the package with full time stamps.
.TP
\fB-c, --configfiles\fR
List only configuration files (implies \fB-l\fR).
.TP
\fB--conflicts\fR
List capabilities this package conflicts with.
.TP
\fB-d, --docfiles\fR
List only documentation files (implies \fB-l\fR).
.TP
\fB--dump\fR
Dump file information as follows (implies \fB-l\fR):
.sp
@ -678,9 +669,6 @@ This uses the \fB--queryformat\fR if one was specified.
Orders the package listing by install time such that the latest
packages are at the top.
.TP
\fB-L, --licensefiles\fR
List only license files (implies \fB-l\fR).
.TP
\fB-l, --list\fR
List files in package.
.TP
@ -716,18 +704,32 @@ Display the \fIstates\fR of files in the package
\fB--triggers, --triggerscripts\fR
Display the trigger scripts, if any, which are contained in
the package.
.TP
\fB--noartifact\fR
Don't display artifact files.
\fB--noghost\fR
Don't display ghost files. Useful in combination with option --list.
.TP
\fB--noconfig\fR
Don't display config files.
.TP
\fB--xml\fR
Format package headers as XML.
.SS "FILE SELECTION OPTIONS:"
.PP
.TP
\fB-d, --artifactfiles\fR
Only include artifact files (implies \fB-l\fR).
.TP
.TP
\fB-c, --configfiles\fR
Only include configuration files (implies \fB-l\fR).
.TP
\fB-d, --docfiles\fR
Only include documentation files (implies \fB-l\fR).
\fB-L, --licensefiles\fR
Only include license files (implies \fB-l\fR).
.TP
\fB--noartifact\fR
Exclude artifact files.
.TP
\fB--noconfig\fR
Exclude config files.
\fB--noghost\fR
Exclude ghost files.
.SS "VERIFY OPTIONS"
.PP
The general form of an rpm verify command is
@ -746,7 +748,7 @@ documentation files excluded on installation using the
"\fB--excludedocs\fR" option,
will be silently ignored.
.PP
The package selection options are the same as for package
The package and file selection options are the same as for package
querying (including package manifest files as arguments).
Other options unique to verify mode are:
.TP
@ -759,12 +761,6 @@ Don't verify package or header digests when reading.
\fB--nofiles\fR
Don't verify any attributes of package files.
.TP
\fB--noghost\fR
Don't verify ghost files.
.TP
\fB--noconfig\fR
Don't verify config files.
.TP
\fB--noscripts\fR
Don't execute the \fB%verifyscript\fR scriptlet (if any).
.TP

View File

@ -178,43 +178,45 @@ static void queryArgCallback(poptContext con,
}
}
/* Duplicate file attr flags from packages into command line options. */
struct poptOption rpmQVFilePoptTable[] = {
{ "configfiles", 'c', POPT_BIT_SET,
&rpmQVKArgs.qva_incattr, RPMFILE_CONFIG,
N_("only include configuration files"), NULL },
{ "docfiles", 'd', POPT_BIT_SET,
&rpmQVKArgs.qva_incattr, RPMFILE_DOC,
N_("only include documentation files"), NULL },
{ "licensefiles", 'L', POPT_BIT_SET,
&rpmQVKArgs.qva_incattr, RPMFILE_LICENSE,
N_("only include license files"), NULL },
{ "artifactfiles", 'A', POPT_BIT_SET,
&rpmQVKArgs.qva_incattr, RPMFILE_ARTIFACT,
N_("only include artifact files"), NULL },
{ "noghost", '\0', POPT_BIT_SET,
&rpmQVKArgs.qva_excattr, RPMFILE_GHOST,
N_("exclude %%ghost files"), NULL },
{ "noconfig", '\0', POPT_BIT_SET,
&rpmQVKArgs.qva_excattr, RPMFILE_CONFIG,
N_("exclude %%config files"), NULL },
{ "noartifact", '\0', POPT_BIT_SET,
&rpmQVKArgs.qva_excattr, RPMFILE_ARTIFACT,
N_("exclude %%artifact files"), NULL },
POPT_TABLEEND
};
/**
* Query mode options.
*/
struct poptOption rpmQueryPoptTable[] = {
/* FIX: cast? */
{ NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
{ NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
queryArgCallback, 0, NULL, NULL },
{ "configfiles", 'c', POPT_BIT_SET,
&rpmQVKArgs.qva_incattr, RPMFILE_CONFIG,
N_("list all configuration files"), NULL },
{ "docfiles", 'd', POPT_BIT_SET,
&rpmQVKArgs.qva_incattr, RPMFILE_DOC,
N_("list all documentation files"), NULL },
{ "licensefiles", 'L', POPT_BIT_SET,
&rpmQVKArgs.qva_incattr, RPMFILE_LICENSE,
N_("list all license files"), NULL },
{ "artifactfiles", 'A', POPT_BIT_SET,
&rpmQVKArgs.qva_incattr, RPMFILE_ARTIFACT,
N_("list all artifact files"), NULL },
{ "dump", '\0', 0, 0, POPT_DUMP,
N_("dump basic file information"), NULL },
{ NULL, 'i', POPT_ARGFLAG_DOC_HIDDEN, 0, 'i',
NULL, NULL },
{ "list", 'l', 0, 0, 'l',
N_("list files in package"), NULL },
/* Duplicate file attr flags from packages into command line options. */
{ "noghost", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
&rpmQVKArgs.qva_excattr, RPMFILE_GHOST,
N_("skip %%ghost files"), NULL },
{ "noconfig", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
&rpmQVKArgs.qva_excattr, RPMFILE_CONFIG,
N_("skip %%config files"), NULL },
{ "noartifact", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
&rpmQVKArgs.qva_excattr, RPMFILE_ARTIFACT,
N_("skip %%artifact files"), NULL },
{ "qf", '\0', POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN, 0,
POPT_QUERYFORMAT, NULL, NULL },
{ "queryformat", '\0', POPT_ARG_STRING, 0, POPT_QUERYFORMAT,

View File

@ -191,6 +191,10 @@ extern struct rpmQVKArguments_s rpmQVKArgs;
*/
extern struct poptOption rpmQVSourcePoptTable[];
/** \ingroup rpmcli
*/
extern struct poptOption rpmQVFilePoptTable[];
/** \ingroup rpmcli
*/
extern struct poptOption rpmQueryPoptTable[];

View File

@ -352,11 +352,12 @@ static const char * stateStr(rpmfileState fstate)
* @param ts transaction set
* @param h header to verify
* @param omitMask bits to disable verify checks
* @param incAttr skip files without these attrs (eg %ghost)
* @param skipAttr skip files with these attrs (eg %ghost)
* @return 0 no problems, 1 problems found
*/
static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask,
rpmfileAttrs skipAttrs)
rpmfileAttrs incAttrs, rpmfileAttrs skipAttrs)
{
rpmVerifyAttrs verifyResult = 0;
rpmVerifyAttrs verifyAll = 0; /* assume no problems */
@ -372,6 +373,10 @@ static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask,
const char *fstate = NULL;
char ac;
/* If filtering by inclusion, skip non-matching (eg --configfiles) */
if (incAttrs && !(incAttrs & fileAttrs))
continue;
/* Skip on attributes (eg from --noghost) */
if (skipAttrs & fileAttrs)
continue;
@ -474,7 +479,8 @@ int showVerifyPackage(QVA_t qva, rpmts ts, Header h)
ec = rc;
}
if (qva->qva_flags & VERIFY_FILES) {
if ((rc = verifyHeader(ts, h, omitMask, qva->qva_excattr)) != 0)
if ((rc = verifyHeader(ts, h, omitMask,
qva->qva_incattr, qva->qva_excattr)) != 0)
ec = rc;
}
if (qva->qva_flags & VERIFY_SCRIPT) {

View File

@ -39,6 +39,9 @@ static struct poptOption optionsTable[] = {
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQVSourcePoptTable, 0,
N_("Query/Verify package selection options:"),
NULL },
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQVFilePoptTable, 0,
N_("Query/Verify file selection options:"),
NULL },
#endif
#ifdef IAM_RPMQ
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,

View File

@ -179,7 +179,7 @@ runroot_other touch /opt/vattrtest/g
runroot_other chmod 644 /opt/vattrtest/g
cmd="rpm -Vv --nouser --nogroup"
for filter in --noconfig --noghost --noartifact; do
for filter in --noconfig --noghost --noartifact -A -c -d -L; do
echo ${filter}
runroot ${cmd} ${filter} vattrtest
done
@ -211,6 +211,15 @@ done
......... l /opt/vattrtest/l
......... m /opt/vattrtest/m
......... r /opt/vattrtest/r
-A
......... a /opt/vattrtest/a
-c
......... c /opt/vattrtest/c
......... c /opt/vattrtest/cn
-d
......... d /opt/vattrtest/d
-L
......... l /opt/vattrtest/l
],
[])
AT_CLEANUP