pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkg/39598: [PATCH] add ability to answer pkg_info -Fe /path/to/file without having bdb



>Number:         39598
>Category:       pkg
>Synopsis:       [PATCH] add ability to answer pkg_info -Fe /path/to/file 
>without having bdb
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Sep 21 18:05:00 +0000 2008
>Originator:     Jens Rehsack
>Release:        -
>Organization:
Bayer Business Services
>Environment:
Linux RHEL4, AIX 5.3 TL8
>Description:
Neither our RHEL4 nor AIX comes with an installed Bekeley DB.
So pkg_info -Fe ... won't work (and neither some other functions which rely on 
file -> pkg resolution).
Because I didn't get pkgtools/pkg_install to use databases/db[24], I decided to 
implement just a "manual" search. Better as fallback and better than even more 
pkg -> (rpm|lpp) dependencies.
>How-To-Repeat:
Bootstrap pkgsrc on RHEL4 or AIX installation without having an 
>Fix:
Index: pkgtools/pkg_install/files/lib/pkgdb.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/pkgdb.c,v
retrieving revision 1.30
diff -u -r1.30 pkgdb.c
--- pkgtools/pkg_install/files/lib/pkgdb.c      29 Apr 2008 05:46:08 -0000      
1.30
+++ pkgtools/pkg_install/files/lib/pkgdb.c      21 Sep 2008 17:38:02 -0000
@@ -70,6 +70,12 @@
 #else
 #define        HAVE_DBLIB      0
 #endif
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#if HAVE_DIRENT_H
+#include <dirent.h>
+#endif
 
 #include "lib.h"
 
@@ -274,10 +280,79 @@
 
 #else /* !HAVE_DBLIB */
 
+static char pkgdb_match[MaxPathSize];
+static int pkgdb_match_found;
+
+static int
+check_pkg_for_file(const char *pkg, void *cookie)
+{
+    package_t plist;
+    struct plist_t *p = NULL;
+    char *where = ".", *contents_file = NULL, tmpfn[MaxPathSize];
+    const char *key = (char *cookie);
+    FILE *fh;
+    
+    contents_file = pkgdb_pkg_file( pkg, CONTENTS_FNAME );
+    fh = open(contents_file, O_RDONLY, 0);
+    free(contents_file);
+    if( NULL == fh )
+    {
+        warn( "cannot read meta data file %s of package %s",
+              CONTENTS_FNAME, pkg );
+        return 0;
+    }
+    read_plist(&plist, fh);
+    close(fh);
+
+    for( p = plist.head; p; p = p->next )
+    {
+        switch( p->type )
+        {
+            case PLIST_CWD:
+                where = p->name;
+                break;
+
+            case PLIST_FILE:
+                snprintf( tmpfn, sizeof(tmpfn), "%s/%s", where, p->name );
+                if( 0 == strcmp( tmpfn, key ) )
+                {
+                    strncpy( pkgdb_match, pkg, sizeof(pkgdb_match) );
+                    ++pkgdb_match_found;
+                    goto found_match;
+                }
+                break;
+
+            default:
+                continue;
+        }
+    }
+
+found_match:
+    free_plist( &plist );
+
+    return pkgdb_match_found;
+}
+/*
+ * assumes given key is a FQPN -> searches pkg name for it in
+ *  _pkgdb_getPKGDB_DIR()/.../+CONTENTS
+ * Return value:
+ *  NULL if some error occurred or value for key not found (check errno!)
+ *  String for "value" else
+ */
+char   *
+pkgdb_retrieve(const char *key)
+{
+    pkgdb_match_found = 0;
+    *pkgdb_match = '\0';
+
+    int errcnt = iterate_pkg_db( check_pkg_for_file, (void *)key );
+
+    return errcnt <= 0 ? NULL : pkgdb_match;
+}
+
 int    pkgdb_open(int mode) { return 1; }
-void   pkgdb_close(void) {}
+void pkgdb_close(void) {}
 int    pkgdb_store(const char *key, const char *val) { return 0; }
-char   *pkgdb_retrieve(const char *key) { return NULL; }
 int    pkgdb_dump(void) { return 0; }
 int    pkgdb_remove(const char *key) { return 0; }
 int    pkgdb_remove_pkg(const char *pkg) { return 1; }



Home | Main Index | Thread Index | Old Index