got --whatrequires, --whatprovides, --requires, --provides, --dump
authorewt <devnull@localhost>
Thu, 20 Jun 1996 22:28:02 +0000 (22:28 +0000)
committerewt <devnull@localhost>
Thu, 20 Jun 1996 22:28:02 +0000 (22:28 +0000)
implemented

CVS patchset: 665
CVS date: 1996/06/20 22:28:02

query.c
query.h
rpm.8
rpm.c

diff --git a/query.c b/query.c
index 92b6c35..7cd14f5 100644 (file)
--- a/query.c
+++ b/query.c
@@ -37,7 +37,6 @@ static char * defaultQueryFormat =
            "Install date: %-27{-INSTALLTIME}   Build Host: %{BUILDHOST}\n"
            "Group       : %-27{GROUP}   Source RPM: %{SOURCERPM}\n"
            "Size        : %{SIZE}\n"
-           "Provides    : %{PROVIDES}\n"
            "Description : %{DESCRIPTION}\n";
 
 static const char * queryHeader(Header h, const char * chptr, int arrayNum) {
@@ -191,15 +190,15 @@ static void printHeader(Header h, int queryFlags, char * queryFormat) {
     char * name, * version, * release;
     int_32 count, type;
     char * prefix = NULL;
-    char ** requiresList, ** strlist;
-    char ** fileList;
+    char ** requiresList, ** strlist, ** providesList;
+    char ** fileList, ** fileMD5List;
     char * fileStatesList;
     char ** fileOwnerList, ** fileGroupList;
     char ** fileLinktoList;
     int_32 * fileFlagsList, * fileMTimeList, * fileSizeList;
     int_32 * fileUIDList, * fileGIDList;
-    int_16 * fileModeList;
-    int_16 * fileRdevList;
+    uint_16 * fileModeList;
+    uint_16 * fileRdevList;
     int i;
 
     getEntry(h, RPMTAG_NAME, &type, (void **) &name, &count);
@@ -217,7 +216,20 @@ static void printHeader(Header h, int queryFlags, char * queryFormat) {
            queryHeader(h, queryFormat, -1);
        }
 
-       if (queryFlags & QUERY_FOR_DEPS) {
+       if (queryFlags & QUERY_FOR_PROVIDES) {
+           printf("Provides    : ");
+           if (!getEntry(h, RPMTAG_PROVIDES, &type, 
+                (void **) &providesList, &count) || !count) {
+               puts("(nothing)");
+           } else {
+               for (i = 0; i < count; i++) {
+                   printf("%s ", providesList[i]);
+               }
+               printf("\n");
+           }
+       }
+
+       if (queryFlags & QUERY_FOR_REQUIRES) {
            printf("Requires    : ");
            if (!getEntry(h, RPMTAG_REQUIRENAME, &type, 
                 (void **) &requiresList, &count) || !count) {
@@ -264,6 +276,8 @@ static void printHeader(Header h, int queryFlags, char * queryFormat) {
                         (void **) &fileGroupList, &count);
                getEntry(h, RPMTAG_FILELINKTOS, &type, 
                         (void **) &fileLinktoList, &count);
+               getEntry(h, RPMTAG_FILEMD5S, &type, 
+                        (void **) &fileMD5List, &count);
 
                for (i = 0; i < count; i++) {
                    if (!((queryFlags & QUERY_FOR_DOCS) || 
@@ -273,25 +287,49 @@ static void printHeader(Header h, int queryFlags, char * queryFormat) {
                        || ((queryFlags & QUERY_FOR_CONFIG) && 
                            (fileFlagsList[i] & RPMFILE_CONFIG))) {
 
-                       if (!isVerbose()) {
+                       if (!isVerbose())
                            prefix ? fputs(prefix, stdout) : 0;
-                           if (queryFlags & QUERY_FOR_STATE) {
-                               if (fileStatesList) {
-                                   switch (fileStatesList[i]) {
-                                     case RPMFILE_STATE_NORMAL:
-                                       fputs("normal        ", stdout); break;
-                                     case RPMFILE_STATE_REPLACED:
-                                       fputs("replaced      ", stdout); break;
-                                     case RPMFILE_STATE_NOTINSTALLED:
-                                       fputs("not installed ", stdout); break;
-                                     default:
-                                       fputs("(unknown)     ", stdout);
-                                   }
-                               } else {
-                                   fputs(    "(no state)    ", stdout);
+
+                       if (queryFlags & QUERY_FOR_STATE) {
+                           if (fileStatesList) {
+                               switch (fileStatesList[i]) {
+                                 case RPMFILE_STATE_NORMAL:
+                                   fputs("normal        ", stdout); break;
+                                 case RPMFILE_STATE_REPLACED:
+                                   fputs("replaced      ", stdout); break;
+                                 case RPMFILE_STATE_NOTINSTALLED:
+                                   fputs("not installed ", stdout); break;
+                                 default:
+                                   fputs("(unknown)     ", stdout);
                                }
+                           } else {
+                               fputs(    "(no state)    ", stdout);
                            }
+                       }
                            
+                       if (queryFlags & QUERY_FOR_DUMPFILES) {
+                           printf("%s %d %d %s 0%o ", fileList[i],
+                                  fileSizeList[i], fileMTimeList[i],
+                                  fileMD5List[i], fileModeList[i]);
+
+                           if (fileOwnerList)
+                               printf("%s %s", fileOwnerList[i], 
+                                               fileGroupList[i]);
+                           else
+                               printf("%d %d", fileUIDList[i], 
+                                               fileGIDList[i]);
+
+                           printf(" %s %s %d ", 
+                                fileFlagsList[i] & RPMFILE_CONFIG ? "1" : "0",
+                                fileFlagsList[i] & RPMFILE_DOC ? "1" : "0",
+                                fileRdevList[i]);
+
+                           if (strlen(fileLinktoList[i]))
+                               printf("%s\n", fileLinktoList[i]);
+                           else
+                               printf("X\n");
+
+                       } else if (!isVerbose()) {
                            puts(fileList[i]);
                        } else if (fileOwnerList) 
                            printFileInfo(fileList[i], fileSizeList[i],
@@ -310,6 +348,7 @@ static void printHeader(Header h, int queryFlags, char * queryFormat) {
            
                free(fileList);
                free(fileLinktoList);
+               free(fileMD5List);
                if (fileOwnerList) free(fileOwnerList);
                if (fileGroupList) free(fileGroupList);
            }
@@ -466,6 +505,7 @@ int doQuery(char * prefix, enum querysources source, int queryFlags,
     dbIndexSet matches;
     int recNumber;
     int retcode = 0;
+    char *end = NULL;
 
     if (source != QUERY_SRPM && source != QUERY_RPM) {
        if (rpmdbOpen(prefix, &db, O_RDONLY, 0644)) {
@@ -530,7 +570,7 @@ int doQuery(char * prefix, enum querysources source, int queryFlags,
        }
        break;
 
-      case QUERY_PROVIDES:
+      case QUERY_WHATPROVIDES:
        if (rpmdbFindByProvides(db, arg, &matches)) {
            fprintf(stderr, "no package provides %s\n", arg);
            retcode = 1;
@@ -540,7 +580,7 @@ int doQuery(char * prefix, enum querysources source, int queryFlags,
        }
        break;
 
-      case QUERY_REQUIREDBY:
+      case QUERY_WHATREQUIRES:
        if (rpmdbFindByRequiredBy(db, arg, &matches)) {
            fprintf(stderr, "no package requires %s\n", arg);
            retcode = 1;
@@ -566,37 +606,37 @@ int doQuery(char * prefix, enum querysources source, int queryFlags,
        }
        break;
 
+      case QUERY_DBOFFSET:
+
       case QUERY_SPACKAGE:
-      case QUERY_PACKAGE:
-       if (queryFlags & QUERY_BY_NUMBER) {
-           char *end = NULL;
-           recNumber = strtoul(arg, &end, 10);
-           if ((*end) || (end == arg) || (recNumber == ULONG_MAX)) {
-               fprintf(stderr, "invalid package number: %s\n", arg);
-               return 1;
-           }
-           message(MESS_DEBUG, "showing package: %d\n", recNumber);
-           h = rpmdbGetRecord(db, recNumber);
+       recNumber = strtoul(arg, &end, 10);
+       if ((*end) || (end == arg) || (recNumber == ULONG_MAX)) {
+           fprintf(stderr, "invalid package number: %s\n", arg);
+           return 1;
+       }
+       message(MESS_DEBUG, "showing package: %d\n", recNumber);
+       h = rpmdbGetRecord(db, recNumber);
 
-           if (!h)  {
-               fprintf(stderr, "record %d could not be read\n", recNumber);
-               retcode = 1;
-           } else {
-               printHeader(h, queryFlags, queryFormat);
-               freeHeader(h);
-           }
+       if (!h)  {
+           fprintf(stderr, "record %d could not be read\n", recNumber);
+           retcode = 1;
        } else {
-           rc = findPackageByLabel(db, arg, &matches);
-           if (rc == 1) {
-               retcode = 1;
-               fprintf(stderr, "package %s is not installed\n", arg);
-           } else if (rc == 2) {
-               retcode = 1;
-               fprintf(stderr, "error looking for package %s\n", arg);
-           } else {
-               showMatches(db, matches, queryFlags, queryFormat);
-               freeDBIndexRecord(matches);
-           }
+           printHeader(h, queryFlags, queryFormat);
+           freeHeader(h);
+       }
+       break;
+
+      case QUERY_PACKAGE:
+       rc = findPackageByLabel(db, arg, &matches);
+       if (rc == 1) {
+           retcode = 1;
+           fprintf(stderr, "package %s is not installed\n", arg);
+       } else if (rc == 2) {
+           retcode = 1;
+           fprintf(stderr, "error looking for package %s\n", arg);
+       } else {
+           showMatches(db, matches, queryFlags, queryFormat);
+           freeDBIndexRecord(matches);
        }
        break;
     }
diff --git a/query.h b/query.h
index 2d37c11..75471b4 100644 (file)
--- a/query.h
+++ b/query.h
@@ -5,7 +5,8 @@
 
 enum querysources { QUERY_PATH, QUERY_PACKAGE, QUERY_ALL, QUERY_SPATH,
                    QUERY_SPACKAGE, QUERY_RPM, QUERY_SRPM, QUERY_GROUP,
-                   QUERY_SGROUP, QUERY_PROVIDES, QUERY_REQUIREDBY };
+                   QUERY_SGROUP, QUERY_WHATPROVIDES, QUERY_WHATREQUIRES,
+                   QUERY_DBOFFSET };
 
 #define QUERY_FOR_INFO                 (1 << 0)
 #define QUERY_FOR_LIST         (1 << 1)
@@ -13,8 +14,9 @@ enum querysources { QUERY_PATH, QUERY_PACKAGE, QUERY_ALL, QUERY_SPATH,
 #define QUERY_FOR_DOCS         (1 << 3)
 #define QUERY_FOR_CONFIG       (1 << 4)
 #define QUERY_FOR_SCRIPTS      (1 << 5)
-#define QUERY_BY_NUMBER         (1 << 6)
-#define QUERY_FOR_DEPS          (1 << 7)
+#define QUERY_FOR_REQUIRES      (1 << 6)
+#define QUERY_FOR_PROVIDES      (1 << 7)
+#define QUERY_FOR_DUMPFILES     (1 << 8)
 
 int doQuery(char * prefix, enum querysources source, int queryFlags, 
             char * arg, char * queryFormat);
diff --git a/rpm.8 b/rpm.8
index 52c46b6..400221a 100644 (file)
--- a/rpm.8
+++ b/rpm.8
@@ -149,9 +149,13 @@ information selection.
 Package selection options:
 .br
 .IP "\fB\fI<package_name>\fP"
-Query pacakge named \fB\fI<package_name>\fP.
+Query package named \fB\fI<package_name>\fP.
 .IP "\fB\-a\fP"
 Query all packages
+.IP "\fB\-whatrequires \fI<capability>\fP"
+Query all packages that requires \fI<capability>\fP for proper functioning.
+.IP "\fB\-whatprovides \fI<virtual>\fP"
+Query all packages that provide the \fI<virtual>\fP capability.
 .IP "\fB\-f \fI<file>\fP"
 Query package owning \fI<file>\fP.
 .IP "\fB\-F\fP"
@@ -165,8 +169,8 @@ Information selection options:
 .br
 .IP "\fB\-i\fP"
 Display package information, including name, version, and description.
-.IP "\fB\-D\fP"
-List packages this one depends on (same as \fB--deps\fP).
+.IP "\fB\-R\fP"
+List packages this one depends on (same as \fB--requires\fP).
 .IP "\fB\-l\fP"
 List files in package.
 .IP "\fB\-s\fP"
@@ -180,6 +184,10 @@ List only configuration files (implies \fB\-l\fP).
 .IP "\fB\-\-scripts\fP"
 List the package specific shell scripts that are used as part of the 
 installation and uninstallation processes, if there are any.
+.IP "\fB\-\-dump\fP"
+Dump file information as follows: path size mtime md5sum mode
+owner group isconfig isdoc rdev symlink. This must be used with
+at least one of \fB\-l\fP, \fB\-c\fP, \fB\-d\fP.
 
 .SH VERIFY OPTIONS
 Verifying a package compares information about the installed
diff --git a/rpm.c b/rpm.c
index 8acf1a9..c19f4d7 100755 (executable)
--- a/rpm.c
+++ b/rpm.c
@@ -62,9 +62,10 @@ void printUsage(void) {
     puts(_("                          [--oldpackage] [--root <dir>] [--noscripts]"));
     puts(_("                          [--excludedocs] [--includedocs] [--rcfile <file>]"));
     puts(_("                          file1.rpm ... fileN.rpm"));
-    puts(_("       rpm {--query -q} [-afFpP] [-i] [-l] [-s] [-d] [-c] [-v] [-D]"));
+    puts(_("       rpm {--query -q} [-afFpP] [-i] [-l] [-s] [-d] [-c] [-v] [-R]"));
     puts(_("                        [--scripts] [--root <dir>] [--rcfile <file>]"));
-    puts(_("                        [--provides] [--deps] [--requiredby] [targets]"));
+    puts(_("                        [--whatprovides] [--whatrequires] [--requires]"));
+    puts(_("                        [--provides] [--dump] [targets]"));
     puts(_("       rpm {--verify -V -y] [-afFpP] [--root <dir>] [--rcfile <file>]"));
     puts(_("                        [targets]"));
     puts(_("       rpm {--erase -e] [--root <dir>] [--noscripts] [--rcfile <file>]"));
@@ -99,16 +100,19 @@ void printHelp(void) {
     puts(_("        -F                - like -f, but read file names from stdin"));
     puts(_("        -p <packagefile>+ - query (uninstalled) package <packagefile>"));
     puts(_("        -P                - like -p, but read package names from stdin"));
-    puts(_("      --provides <item>  - query packages which provide <item> capability"));
-    puts(_("      --requiredby <item> - query packages which require <item> capability"));
+    puts(_("      --whatprovides <i> - query packages which provide <i> capability"));
+    puts(_("      --whatrequires <i> - query packages which require <i> capability"));
     puts(_("      Information selection options:"));
     puts(_("        -i                - display package information"));
     puts(_("        -l                - display package file list"));
     puts(_("        -s                - show file states (implies -l)"));
     puts(_("        -d                - list only documentation files (implies -l)"));
     puts(_("        -c                - list only configuration files (implies -l)"));
-    puts(_("        --deps"));
-    puts(_("        -D                - list package dependencies"));
+    puts(_("        --dump            - show all verifiable information for each file"));
+    puts(_("                            (must be used with -l, -c, or -d)"));
+    puts(_("        --provides        - list capabilbities package provides"));
+    puts(_("        --requires"));
+    puts(_("        -R                - list package dependencies"));
     puts(_("        --scripts         - print the various [un]install scripts"));
     puts(_(""));
     puts(_("    -V"));
@@ -223,7 +227,7 @@ int main(int argc, char ** argv) {
     int buildAmount = 0, oldPackage = 0, clean = 0, signIt = 0;
     int shortCircuit = 0, badOption = 0, queryTags = 0, excldocs = 0;
     int incldocs = 0, queryScripts = 0, noScripts = 0, noDeps = 0;
-    int noPgp = 0;
+    int noPgp = 0, dump = 0;
     char * rcfile = NULL;
     char * queryFormat = NULL;
     char buildChar = ' ';
@@ -239,8 +243,8 @@ int main(int argc, char ** argv) {
            { "checksig", 0, 0, 'K' },
            { "clean", 0, &clean, 0 },
            { "configfiles", 0, 0, 'c' },
-           { "deps", 0, 0, 'D' },
            { "docfiles", 0, 0, 'd' },
+           { "dump", 0, &dump, 0 },
            { "erase", 0, 0, 'e' },
             { "excludedocs", 0, &excldocs, 0},
            { "file", 0, 0, 'f' },
@@ -270,7 +274,7 @@ int main(int argc, char ** argv) {
            { "replacefiles", 0, &replaceFiles, 0 },
            { "replacepkgs", 0, &replacePackages, 0 },
            { "resign", 0, 0, 0 },
-           { "requiredby", 0, 0, 0 },
+           { "requires", 0, 0, 'R' },
            { "root", 1, 0, 'r' },
            { "scripts", 0, &queryScripts, 0 },
            { "short-circuit", 0, &shortCircuit, 0 },
@@ -286,6 +290,8 @@ int main(int argc, char ** argv) {
            { "verbose", 0, 0, 'v' },
            { "verify", 0, 0, 'V' },
            { "version", 0, &version, 0 },
+           { "whatrequires", 0, 0, 0 },
+           { "whatprovides", 0, 0, 0 },
            { 0, 0, 0, 0 } 
        } ;
 
@@ -425,8 +431,8 @@ int main(int argc, char ** argv) {
            queryFor |= QUERY_FOR_LIST | QUERY_FOR_STATE;
            break;
 
-         case 'D':
-           queryFor |= QUERY_FOR_DEPS;
+         case 'R':
+           queryFor |= QUERY_FOR_REQUIRES;
            break;
 
          case 'l':
@@ -510,18 +516,20 @@ int main(int argc, char ** argv) {
          default:
            if (options[long_index].flag)
                *options[long_index].flag = 1;
-           else if (!strcmp(options[long_index].name, "requiredby")) {
+           else if (!strcmp(options[long_index].name, "whatrequires")) {
                if (querySource != QUERY_PACKAGE && 
-                   querySource != QUERY_REQUIREDBY)
+                   querySource != QUERY_WHATREQUIRES)
                    argerror(_("one type of query/verify may be performed at a "
                                    "time"));
-               querySource = QUERY_REQUIREDBY;
-           } else if (!strcmp(options[long_index].name, "provides")) {
+               querySource = QUERY_WHATREQUIRES;
+           } else if (!strcmp(options[long_index].name, "whatprovides")) {
                if (querySource != QUERY_PACKAGE && 
-                   querySource != QUERY_PROVIDES)
+                   querySource != QUERY_WHATPROVIDES)
                    argerror(_("one type of query/verify may be performed at a "
                                    "time"));
-               querySource = QUERY_PROVIDES;
+               querySource = QUERY_WHATPROVIDES;
+           } else if (!strcmp(options[long_index].name, "provides")) {
+               queryFor |= QUERY_FOR_PROVIDES;
            } else if (!strcmp(options[long_index].name, "rebuild")) {
                if (bigMode != MODE_UNKNOWN && bigMode != MODE_REBUILD)
                    argerror(_("only one major mode may be specified"));
@@ -536,10 +544,10 @@ int main(int argc, char ** argv) {
                bigMode = MODE_RESIGN;
                signIt = 1;
            } else if (!strcmp(options[long_index].name, "querybynumber")) {
-               if (bigMode != MODE_UNKNOWN && bigMode != MODE_QUERY)
-                   argerror(_("only one major mode may be specified"));
-               bigMode = MODE_QUERY;
-               queryFor |= QUERY_BY_NUMBER;
+               if (querySource != QUERY_PACKAGE && querySource != QUERY_RPM)
+                   argerror(_("one type of query may be performed at a " "time"));
+               querySource = QUERY_DBOFFSET;
+               verifySource = VERIFY_RPM;
            } else if (!strcmp(options[long_index].name, "queryformat")) {
                if (bigMode != MODE_UNKNOWN && bigMode != MODE_QUERY)
                    argerror(_("only one major mode may be specified"));
@@ -637,6 +645,12 @@ int main(int argc, char ** argv) {
     if (oldPackage && !(installFlags & INSTALL_UPGRADE))
        argerror(_("--oldpackage may only be used during upgrades"));
 
+    if (bigMode != MODE_QUERY && dump) 
+       argerror(_("--dump may only be used during queryies"));
+
+    if (bigMode == MODE_QUERY && dump && !(queryFor & QUERY_FOR_LIST))
+       argerror(_("--dump of queries must be used with -l, -c, or -d"));
+
     if (oldPackage || (force && (installFlags & INSTALL_UPGRADE)))
        installFlags |= INSTALL_UPGRADETOOLD;
 
@@ -781,6 +795,8 @@ int main(int argc, char ** argv) {
        break;
 
       case MODE_QUERY:
+       if (dump) queryFor |= QUERY_FOR_DUMPFILES;
+
        if (querySource == QUERY_ALL) {
            if (optind != argc) 
                argerror(_("extra arguments given for query of all packages"));