Преглед изворни кода

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 пре 16 година
родитељ
комит
15daa22fa9
6 измењених фајлова са 16 додато и 14 уклоњено
  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 int updateslength;
 static char *updatefnbuf, *updatefnrest;
 static char *updatefnbuf, *updatefnrest;
 static const char *admindir;
 static const char *admindir;
+static char *infodir;
 static struct varbuf uvb;
 static struct varbuf uvb;
 
 
 static int ulist_select(const struct dirent *de) {
 static int ulist_select(const struct dirent *de) {
@@ -133,6 +134,7 @@ static const struct fni {
   {   STATUSFILE,                 &statusfile         },
   {   STATUSFILE,                 &statusfile         },
   {   AVAILFILE,                  &availablefile      },
   {   AVAILFILE,                  &availablefile      },
   {   UPDATESDIR IMPORTANTTMP,    &importanttmpfile   },
   {   UPDATESDIR IMPORTANTTMP,    &importanttmpfile   },
+  {   INFODIR,                    &infodir            },
   {   NULL, NULL                                      }
   {   NULL, NULL                                      }
 };
 };
 
 
@@ -360,11 +362,16 @@ modstatdb_note_ifwrite(struct pkginfo *pkg)
     modstatdb_note(pkg);
     modstatdb_note(pkg);
 }
 }
 
 
+const char *
+pkgadmindir(void)
+{
+  return infodir;
+}
+
 const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile) {
 const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile) {
   static struct varbuf vb;
   static struct varbuf vb;
   varbufreset(&vb);
   varbufreset(&vb);
-  varbufaddstr(&vb,admindir);
-  varbufaddstr(&vb,"/" INFODIR);
+  varbufaddstr(&vb, infodir);
   varbufaddstr(&vb,pkg->name);
   varbufaddstr(&vb,pkg->name);
   varbufaddc(&vb,'.');
   varbufaddc(&vb,'.');
   varbufaddstr(&vb,whichfile);
   varbufaddstr(&vb,whichfile);

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

@@ -211,6 +211,7 @@ void modstatdb_shutdown(void);
 /* Initialised by modstatdb_init. */
 /* Initialised by modstatdb_init. */
 extern char *statusfile, *availablefile;
 extern char *statusfile, *availablefile;
 
 
+const char *pkgadmindir(void);
 const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile);
 const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile);
 
 
 /*** from trigdeferred.l ***/
 /*** 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;
   FILE *file;
 
 
   varbufreset(&vb);
   varbufreset(&vb);
-  varbufaddstr(&vb,admindir);
-  varbufaddstr(&vb,"/" INFODIR);
+  varbufaddstr(&vb, pkgadmindir());
   varbufaddstr(&vb,pkg->name);
   varbufaddstr(&vb,pkg->name);
   varbufaddstr(&vb,"." LISTFILE);
   varbufaddstr(&vb,"." LISTFILE);
   varbufaddc(&vb,0);
   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");
   debug(dbg_general, "process_archive updating info directory");
   varbufreset(&infofnvb);
   varbufreset(&infofnvb);
-  varbufaddstr(&infofnvb,admindir);
-  varbufaddstr(&infofnvb, "/" INFODIR);
+  varbufaddstr(&infofnvb, pkgadmindir());
   infodirlen= infofnvb.used;
   infodirlen= infofnvb.used;
   varbufaddc(&infofnvb,0);
   varbufaddc(&infofnvb,0);
   dsd= opendir(infofnvb.buf);
   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 .. */
     /* OK, now we delete all the stuff in the `info' directory .. */
     varbufreset(&fnvb);
     varbufreset(&fnvb);
-    varbufaddstr(&fnvb,admindir);
-    varbufaddstr(&fnvb,"/" INFODIR);
+    varbufaddstr(&fnvb, pkgadmindir());
     infodirbaseused= fnvb.used;
     infodirbaseused= fnvb.used;
     varbufaddc(&fnvb,0);
     varbufaddc(&fnvb,0);
     dsd= opendir(fnvb.buf); if (!dsd) ohshite(_("cannot read info directory"));
     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;
   size_t db_path_len;
 
 
   varbufinit(&db_path, 0);
   varbufinit(&db_path, 0);
-  varbufaddstr(&db_path, admindir);
-  varbufaddstr(&db_path, "/" INFODIR);
+  varbufaddstr(&db_path, pkgadmindir());
   db_path_len = db_path.used;
   db_path_len = db_path.used;
   varbufaddc(&db_path, '\0');
   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",
     maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
                                 "remove", NULL);
                                 "remove", NULL);
     varbufreset(&fnvb);
     varbufreset(&fnvb);
-    varbufaddstr(&fnvb,admindir);
-    varbufaddstr(&fnvb,"/" INFODIR);
+    varbufaddstr(&fnvb, pkgadmindir());
     infodirbaseused= fnvb.used;
     infodirbaseused= fnvb.used;
     varbufaddc(&fnvb,0);
     varbufaddc(&fnvb,0);
     dsd= opendir(fnvb.buf); if (!dsd) ohshite(_("cannot read info directory"));
     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);
     removal_bulk_remove_leftover_dirs(pkg);
 
 
     varbufreset(&fnvb);
     varbufreset(&fnvb);
-    varbufaddstr(&fnvb,admindir);
-    varbufaddstr(&fnvb,"/" INFODIR);
+    varbufaddstr(&fnvb, pkgadmindir());
     varbufaddstr(&fnvb,pkg->name);
     varbufaddstr(&fnvb,pkg->name);
     pkgnameused= fnvb.used;
     pkgnameused= fnvb.used;