Explorar el Código

libdpkg: Create new pkgadmindir() to hide admindir and INFODIR

The callers should not be concerned about where the package info
directory is located, the new functions encapsulates the knowdlegde
in the dbmodify module.
Guillem Jover hace 16 años
padre
commit
15daa22fa9
Se han modificado 6 ficheros con 16 adiciones y 14 borrados
  1. 9 2
      lib/dpkg/dbmodify.c
  2. 1 0
      lib/dpkg/dpkg-db.h
  3. 1 2
      src/filesdb.c
  4. 2 4
      src/processarc.c
  5. 1 2
      src/query.c
  6. 2 4
      src/remove.c

+ 9 - 2
lib/dpkg/dbmodify.c

@@ -52,6 +52,7 @@ static int nextupdate;
 static int updateslength;
 static char *updatefnbuf, *updatefnrest;
 static const char *admindir;
+static char *infodir;
 static struct varbuf uvb;
 
 static int ulist_select(const struct dirent *de) {
@@ -133,6 +134,7 @@ static const struct fni {
   {   STATUSFILE,                 &statusfile         },
   {   AVAILFILE,                  &availablefile      },
   {   UPDATESDIR IMPORTANTTMP,    &importanttmpfile   },
+  {   INFODIR,                    &infodir            },
   {   NULL, NULL                                      }
 };
 
@@ -360,11 +362,16 @@ modstatdb_note_ifwrite(struct pkginfo *pkg)
     modstatdb_note(pkg);
 }
 
+const char *
+pkgadmindir(void)
+{
+  return infodir;
+}
+
 const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile) {
   static struct varbuf vb;
   varbufreset(&vb);
-  varbufaddstr(&vb,admindir);
-  varbufaddstr(&vb,"/" INFODIR);
+  varbufaddstr(&vb, infodir);
   varbufaddstr(&vb,pkg->name);
   varbufaddc(&vb,'.');
   varbufaddstr(&vb,whichfile);

+ 1 - 0
lib/dpkg/dpkg-db.h

@@ -211,6 +211,7 @@ void modstatdb_shutdown(void);
 /* Initialised by modstatdb_init. */
 extern char *statusfile, *availablefile;
 
+const char *pkgadmindir(void);
 const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile);
 
 /*** from trigdeferred.l ***/

+ 1 - 2
src/filesdb.c

@@ -403,8 +403,7 @@ void write_filelist_except(struct pkginfo *pkg, struct fileinlist *list, int lea
   FILE *file;
 
   varbufreset(&vb);
-  varbufaddstr(&vb,admindir);
-  varbufaddstr(&vb,"/" INFODIR);
+  varbufaddstr(&vb, pkgadmindir());
   varbufaddstr(&vb,pkg->name);
   varbufaddstr(&vb,"." LISTFILE);
   varbufaddc(&vb,0);

+ 2 - 4
src/processarc.c

@@ -815,8 +815,7 @@ void process_archive(const char *filename) {
    */
   debug(dbg_general, "process_archive updating info directory");
   varbufreset(&infofnvb);
-  varbufaddstr(&infofnvb,admindir);
-  varbufaddstr(&infofnvb, "/" INFODIR);
+  varbufaddstr(&infofnvb, pkgadmindir());
   infodirlen= infofnvb.used;
   varbufaddc(&infofnvb,0);
   dsd= opendir(infofnvb.buf);
@@ -1064,8 +1063,7 @@ void process_archive(const char *filename) {
 
     /* OK, now we delete all the stuff in the `info' directory .. */
     varbufreset(&fnvb);
-    varbufaddstr(&fnvb,admindir);
-    varbufaddstr(&fnvb,"/" INFODIR);
+    varbufaddstr(&fnvb, pkgadmindir());
     infodirbaseused= fnvb.used;
     varbufaddc(&fnvb,0);
     dsd= opendir(fnvb.buf); if (!dsd) ohshite(_("cannot read info directory"));

+ 1 - 2
src/query.c

@@ -469,8 +469,7 @@ control_path_pkg(struct pkginfo *pkg)
   size_t db_path_len;
 
   varbufinit(&db_path, 0);
-  varbufaddstr(&db_path, admindir);
-  varbufaddstr(&db_path, "/" INFODIR);
+  varbufaddstr(&db_path, pkgadmindir());
   db_path_len = db_path.used;
   varbufaddc(&db_path, '\0');
 

+ 2 - 4
src/remove.c

@@ -264,8 +264,7 @@ static void removal_bulk_remove_files(
     maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
                                 "remove", NULL);
     varbufreset(&fnvb);
-    varbufaddstr(&fnvb,admindir);
-    varbufaddstr(&fnvb,"/" INFODIR);
+    varbufaddstr(&fnvb, pkgadmindir());
     infodirbaseused= fnvb.used;
     varbufaddc(&fnvb,0);
     dsd= opendir(fnvb.buf); if (!dsd) ohshite(_("cannot read info directory"));
@@ -546,8 +545,7 @@ void removal_bulk(struct pkginfo *pkg) {
     removal_bulk_remove_leftover_dirs(pkg);
 
     varbufreset(&fnvb);
-    varbufaddstr(&fnvb,admindir);
-    varbufaddstr(&fnvb,"/" INFODIR);
+    varbufaddstr(&fnvb, pkgadmindir());
     varbufaddstr(&fnvb,pkg->name);
     pkgnameused= fnvb.used;