Sfoglia il codice sorgente

libdpkg: Namespace package database functions with pkg_db_ prefix

Guillem Jover 15 anni fa
parent
commit
9db4a822bb

+ 0 - 1
TODO

@@ -46,7 +46,6 @@ TODO
    - Replace raw write and read calls with safe variants (signals etc).
    - Make deb build version a version instead of doing checks over a string.
    - Use enums for currently hardcoded literals (tdus, dependtry, etc).
-   - Namespace pkg_db funcs.
    - Do not use nfmalloc (and friends) for non in-core db memory.
    - Call nffreeall on exit (need to detangle nfmalloc from non-db first).
    - Add a size parameter to the buffer api to avoid some useless

+ 1 - 1
dselect/main.cc

@@ -365,7 +365,7 @@ urqresult urq_list(void) {
   delete l;
 
   modstatdb_shutdown();
-  resetpackages();
+  pkg_db_reset();
   return urqr_normal;
 }
 

+ 5 - 4
dselect/pkglist.cc

@@ -356,7 +356,7 @@ void packagelist::initialsetup() {
   if (debug)
     fprintf(debug,"packagelist[%p]::initialsetup()\n",this);
 
-  int allpackages= countpackages();
+  int allpackages = pkg_db_count();
   datatable= new struct perpackagestate[allpackages];
 
   nallocated= allpackages+150; // will realloc if necessary, so 150 not critical
@@ -386,8 +386,9 @@ packagelist::packagelist(keybindings *kb) : baselist(kb) {
   struct pkginfo *pkg;
   
   nitems = 0;
-  iter = iterpkgstart();
-  while ((pkg = iterpkgnext(iter))) {
+
+  iter = pkg_db_iter_new();
+  while ((pkg = pkg_db_iter_next(iter))) {
     struct perpackagestate *state= &datatable[nitems];
     state->pkg= pkg;
     if (pkg->status == pkginfo::stat_notinstalled &&
@@ -415,7 +416,7 @@ packagelist::packagelist(keybindings *kb) : baselist(kb) {
     table[nitems]= state;
     nitems++;
   }
-  iterpkgend(iter);
+  pkg_db_iter_free(iter);
 
   if (!nitems)
     ohshit(_("There are no packages."));

+ 18 - 6
lib/dpkg/database.c

@@ -120,7 +120,9 @@ informative(struct pkginfo *pkg, struct pkginfoperfile *info)
   return false;
 }
 
-struct pkginfo *findpackage(const char *inname) {
+struct pkginfo *
+pkg_db_find(const char *inname)
+{
   struct pkginfo **pointerp, *newpkg;
   char *name = m_strdup(inname), *p;
 
@@ -143,7 +145,9 @@ struct pkginfo *findpackage(const char *inname) {
   return newpkg;
 }
 
-int countpackages(void) {
+int
+pkg_db_count(void)
+{
   return npackages;
 }
 
@@ -152,7 +156,9 @@ struct pkgiterator {
   int nbinn;
 };
 
-struct pkgiterator *iterpkgstart(void) {
+struct pkgiterator *
+pkg_db_iter_new(void)
+{
   struct pkgiterator *i;
   i= m_malloc(sizeof(struct pkgiterator));
   i->pigp= NULL;
@@ -160,7 +166,9 @@ struct pkgiterator *iterpkgstart(void) {
   return i;
 }
 
-struct pkginfo *iterpkgnext(struct pkgiterator *i) {
+struct pkginfo *
+pkg_db_iter_next(struct pkgiterator *i)
+{
   struct pkginfo *r;
   while (!i->pigp) {
     if (i->nbinn >= BINS) return NULL;
@@ -169,11 +177,15 @@ struct pkginfo *iterpkgnext(struct pkgiterator *i) {
   r= i->pigp; i->pigp= r->next; return r;
 }
 
-void iterpkgend(struct pkgiterator *i) {
+void
+pkg_db_iter_free(struct pkgiterator *i)
+{
   free(i);
 }
 
-void resetpackages(void) {
+void
+pkg_db_reset(void)
+{
   int i;
   nffreeall();
   npackages= 0;

+ 7 - 6
lib/dpkg/dpkg-db.h

@@ -213,17 +213,18 @@ const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile);
 
 /*** from database.c ***/
 
-struct pkginfo *findpackage(const char *name);
 void blankpackage(struct pkginfo *pp);
 void blankpackageperfile(struct pkginfoperfile *pifp);
 void blankversion(struct versionrevision*);
 bool informative(struct pkginfo *pkg, struct pkginfoperfile *info);
-int countpackages(void);
-void resetpackages(void);
 
-struct pkgiterator *iterpkgstart(void);
-struct pkginfo *iterpkgnext(struct pkgiterator*);
-void iterpkgend(struct pkgiterator*);
+struct pkginfo *pkg_db_find(const char *name);
+int pkg_db_count(void);
+void pkg_db_reset(void);
+
+struct pkgiterator *pkg_db_iter_new(void);
+struct pkginfo *pkg_db_iter_next(struct pkgiterator *iter);
+void pkg_db_iter_free(struct pkgiterator *iter);
 
 void hashreport(FILE*);
 

+ 3 - 3
lib/dpkg/dump.c

@@ -382,8 +382,8 @@ writedb(const char *filename, bool available, bool mustsync)
   if (setvbuf(file,writebuf,_IOFBF,sizeof(writebuf)))
     ohshite(_("unable to set buffering on %s database file"), which);
 
-  it= iterpkgstart();
-  while ((pigp= iterpkgnext(it)) != NULL) {
+  it = pkg_db_iter_new();
+  while ((pigp = pkg_db_iter_next(it)) != NULL) {
     pifp= available ? &pigp->available : &pigp->installed;
     /* Don't dump records which have no useful content. */
     if (!informative(pigp,pifp)) continue;
@@ -394,7 +394,7 @@ writedb(const char *filename, bool available, bool mustsync)
               which, pigp->name, filename);
     varbufreset(&vb);      
   }
-  iterpkgend(it);
+  pkg_db_iter_free(it);
   varbuf_destroy(&vb);
   if (mustsync) {
     if (fflush(file))

+ 4 - 6
lib/dpkg/fields.c

@@ -73,10 +73,8 @@ f_name(struct pkginfo *pigp, struct pkginfoperfile *pifp,
   const char *e;
   if ((e= illegal_packagename(value,NULL)) != NULL)
     parse_error(ps, pigp, _("invalid package name (%.250s)"), e);
-  pigp->name= findpackage(value)->name;
-  /* We use the new name, as findpackage() may have
-     done a tolower for us.
-   */
+  /* We use the new name, as pkg_db_find() may have done a tolower for us. */
+  pigp->name = pkg_db_find(value)->name;
 }
 
 void f_filecharf(struct pkginfo *pigp, struct pkginfoperfile *pifp,
@@ -331,7 +329,7 @@ void f_dependency(struct pkginfo *pigp, struct pkginfoperfile *pifp,
                     fip->name, depname.buf, emsg);
       dop= nfmalloc(sizeof(struct deppossi));
       dop->up= dyp;
-      dop->ed = findpackage(depname.buf);
+      dop->ed = pkg_db_find(depname.buf);
       dop->next= NULL; *ldopp= dop; ldopp= &dop->next;
 
       /* Don't link this (which is after all only ‘newpig’ from
@@ -524,7 +522,7 @@ f_trigaw(struct pkginfo *aw, struct pkginfoperfile *pifp,
       parse_error(ps, aw,
                   _("illegal package name in awaited trigger `%.255s': %s"),
                   word, emsg);
-    pend = findpackage(word);
+    pend = pkg_db_find(word);
 
     if (!trig_note_aw(pend, aw))
       parse_error(ps, aw,

+ 6 - 6
lib/dpkg/libdpkg.Versions

@@ -194,12 +194,12 @@ LIBDPKG_PRIVATE {
 	pkg_format_free;
 
 	# Package in-core database functions
-	findpackage;
-	countpackages;
-	resetpackages;
-	iterpkgstart;
-	iterpkgnext;
-	iterpkgend;
+	pkg_db_find;
+	pkg_db_count;
+	pkg_db_reset;
+	pkg_db_iter_new;
+	pkg_db_iter_next;
+	pkg_db_iter_free;
 
 	# Package on-disk database functions
 	statusinfos;		# XXX variable, do not export

+ 2 - 2
lib/dpkg/parse.c

@@ -331,7 +331,7 @@ int parsedb(const char *filename, enum parsedbflags flags,
       newpig.want = want_unknown;
     }
 
-    pigp= findpackage(newpig.name);
+    pigp = pkg_db_find(newpig.name);
     pifp= (flags & pdb_recordavailable) ? &pigp->available : &pigp->installed;
 
     if ((flags & pdb_ignoreolder) &&
@@ -375,7 +375,7 @@ int parsedb(const char *filename, enum parsedbflags flags,
       for (ta = pigp->trigaw.head; ta; ta = ta->sameaw.next) {
         assert(ta->aw == &newpig);
         ta->aw = pigp;
-        /* ->othertrigaw_head is updated by trig_note_aw in *(findpackage())
+        /* ->othertrigaw_head is updated by trig_note_aw in *(pkg_db_find())
          * rather than in newpig */
       }
 

+ 4 - 4
lib/dpkg/pkg-array.c

@@ -42,13 +42,13 @@ pkg_array_init_from_db(struct pkg_array *a)
 	struct pkginfo *pkg;
 	int i;
 
-	a->n_pkgs = countpackages();
+	a->n_pkgs = pkg_db_count();
 	a->pkgs = m_malloc(sizeof(a->pkgs[0]) * a->n_pkgs);
 
-	it = iterpkgstart();
-	for (i = 0; (pkg = iterpkgnext(it)); i++)
+	it = pkg_db_iter_new();
+	for (i = 0; (pkg = pkg_db_iter_next(it)); i++)
 		a->pkgs[i] = pkg;
-	iterpkgend(it);
+	pkg_db_iter_free(it);
 
 	assert(i == a->n_pkgs);
 }

+ 4 - 4
lib/dpkg/triglib.c

@@ -155,7 +155,7 @@ trig_note_pend(struct pkginfo *pend, const char *trig /*not copied!*/)
 
 /* Returns: true for done, false for already noted. */
 /* NB that this is called also from fields.c where *aw is a temporary
- * but pend is from findpackage()! */
+ * but pend is from pkg_db_find()! */
 bool
 trig_note_aw(struct pkginfo *pend, struct pkginfo *aw)
 {
@@ -390,7 +390,7 @@ trk_explicit_activate_awaiter(struct pkginfo *aw)
 			ohshit(_("trigger interest file `%.250s' syntax error; "
 			         "illegal package name `%.250s': %.250s"),
 			       trk_explicit_fn.buf, buf, emsg);
-		pend = findpackage(buf);
+		pend = pkg_db_find(buf);
 		trig_record_activation(pend, aw, trk_explicit_trig);
 	}
 }
@@ -584,7 +584,7 @@ trig_file_interests_ensure(void)
 			ohshit(_("file triggers record mentions illegal "
 			         "package name `%.250s' (for interest in file "
 				 "`%.250s'): %.250s"), space, linebuf, emsg);
-		pkg = findpackage(space);
+		pkg = pkg_db_find(space);
 		trk_file_interest_change(linebuf, pkg, +2);
 	}
 	pop_cleanup(ehflag_normaltidy);
@@ -742,7 +742,7 @@ tdm_incorp_trig_begin(const char *trig)
 static void
 tdm_incorp_package(const char *awname)
 {
-	struct pkginfo *aw = strcmp(awname, "-") ? findpackage(awname) : NULL;
+	struct pkginfo *aw = strcmp(awname, "-") ? pkg_db_find(awname) : NULL;
 
 	dtki->activate_awaiter(aw);
 }

+ 3 - 3
src/depcon.c

@@ -158,11 +158,11 @@ findbreakcycle(struct pkginfo *pkg)
   struct pkginfo *tpkg;
 	
   /* Clear the visited flag of all packages before we traverse them. */
-  iter = iterpkgstart();
-  while ((tpkg = iterpkgnext(iter))) {
+  iter = pkg_db_iter_new();
+  while ((tpkg = pkg_db_iter_next(iter))) {
     tpkg->clientdata->color = white;
   }
-  iterpkgend(iter);
+  pkg_db_iter_free(iter);
 
   return findbreakcyclerecursive(pkg, NULL);
 }

+ 2 - 2
src/divertcmd.c

@@ -453,7 +453,7 @@ diversion_add(const char *const *argv)
 	if (opt_pkgname == NULL)
 		pkg = NULL;
 	else
-		pkg = findpackage(opt_pkgname);
+		pkg = pkg_db_find(opt_pkgname);
 
 	/* Check we are not stomping over an existing diversion. */
 	if (fnn_from->divert || fnn_to->divert) {
@@ -528,7 +528,7 @@ diversion_remove(const char *const *argv)
 	if (opt_pkgname == NULL)
 		pkg = NULL;
 	else
-		pkg = findpackage(opt_pkgname);
+		pkg = pkg_db_find(opt_pkgname);
 
 	contest = namenode->divert;
 	altname = contest->useinstead->divert;

+ 1 - 1
src/divertdb.c

@@ -108,7 +108,7 @@ ensure_diversions(void)
 
 		fgets_must(linebuf, sizeof(linebuf), file, vb.buf);
 		oicontest->pkg = oialtname->pkg = strcmp(linebuf, ":") ?
-		                                  findpackage(linebuf) : NULL;
+		                                  pkg_db_find(linebuf) : NULL;
 
 		if (oialtname->camefrom->divert ||
 		    oicontest->useinstead->divert)

+ 16 - 16
src/enquiry.c

@@ -140,8 +140,8 @@ void audit(const char *const *argv) {
     struct pkginfo *pkg;
     bool head = false;
 
-    it= iterpkgstart(); 
-    while ((pkg= iterpkgnext(it))) {
+    it = pkg_db_iter_new();
+    while ((pkg = pkg_db_iter_next(it))) {
       if (!bsi->yesno(pkg,bsi)) continue;
       if (!head_running) {
         if (modstatdb_is_locked(admindir))
@@ -156,7 +156,7 @@ void audit(const char *const *argv) {
       }
       describebriefly(pkg);
     }
-    iterpkgend(it);
+    pkg_db_iter_free(it);
     if (head) putchar('\n');
   }
 
@@ -207,8 +207,8 @@ void unpackchk(const char *const *argv) {
   totalcount= 0;
   sectionentries = NULL;
   sects= 0;
-  it= iterpkgstart(); 
-  while ((pkg= iterpkgnext(it))) {
+  it = pkg_db_iter_new();
+  while ((pkg = pkg_db_iter_next(it))) {
     if (!yettobeunpacked(pkg, &thissect)) continue;
     for (se= sectionentries; se && strcasecmp(thissect,se->name); se= se->next);
     if (!se) {
@@ -224,33 +224,33 @@ void unpackchk(const char *const *argv) {
     }
     se->count++; totalcount++;
   }
-  iterpkgend(it);
+  pkg_db_iter_free(it);
 
   if (totalcount == 0) exit(0);
   
   if (totalcount <= 12) {
-    it= iterpkgstart(); 
-    while ((pkg= iterpkgnext(it))) {
+    it = pkg_db_iter_new();
+    while ((pkg = pkg_db_iter_next(it))) {
       if (!yettobeunpacked(pkg, NULL))
         continue;
       describebriefly(pkg);
     }
-    iterpkgend(it);
+    pkg_db_iter_free(it);
   } else if (sects <= 12) {
     for (se= sectionentries; se; se= se->next) {
       sprintf(buf,"%d",se->count);
       printf(_(" %d in %s: "),se->count,se->name);
       width= 70-strlen(se->name)-strlen(buf);
       while (width > 59) { putchar(' '); width--; }
-      it= iterpkgstart(); 
-      while ((pkg= iterpkgnext(it))) {
+      it = pkg_db_iter_new();
+      while ((pkg = pkg_db_iter_next(it))) {
         if (!yettobeunpacked(pkg,&thissect)) continue;
         if (strcasecmp(thissect,se->name)) continue;
         width -= strlen(pkg->name); width--;
         if (width < 4) { printf(" ..."); break; }
         printf(" %s",pkg->name);
       }
-      iterpkgend(it);
+      pkg_db_iter_free(it);
       putchar('\n');
     }
   } else {
@@ -282,7 +282,7 @@ assert_version_support(const char *const *argv,
 
   modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail);
 
-  pkg= findpackage("dpkg");
+  pkg = pkg_db_find("dpkg");
   switch (pkg->status) {
   case stat_installed:
   case stat_triggerspending:
@@ -347,8 +347,8 @@ void predeppackage(const char *const *argv) {
   clear_istobes(); /* We use clientdata->istobe to detect loops */
 
   dep = NULL;
-  it = iterpkgstart();
-  while (!dep && (pkg = iterpkgnext(it))) {
+  it = pkg_db_iter_new();
+  while (!dep && (pkg = pkg_db_iter_next(it))) {
     if (pkg->want != want_install) continue; /* Ignore packages user doesn't want */
     if (!pkg->files) continue; /* Ignore packages not available */
     pkg->clientdata->istobe= itb_preinstall;
@@ -361,7 +361,7 @@ void predeppackage(const char *const *argv) {
     pkg->clientdata->istobe= itb_normal;
     /* If dep is NULL we go and get the next package. */
   }
-  iterpkgend(it);
+  pkg_db_iter_free(it);
 
   if (!dep) exit(1); /* Not found */
   assert(pkg);

+ 1 - 1
src/filesdb.c

@@ -419,7 +419,7 @@ void ensure_allinstfiles_available(void) {
 
   if (allpackagesdone) return;
   if (saidread<2) {
-    int max = countpackages();
+    int max = pkg_db_count();
 
     saidread=1;
     progress_init(&progress, _("(Reading database ... "), max);

+ 3 - 3
src/help.c

@@ -443,13 +443,13 @@ void clear_istobes(void) {
   struct pkgiterator *it;
   struct pkginfo *pkg;
 
-  it= iterpkgstart();
-  while ((pkg = iterpkgnext(it)) != NULL) {
+  it = pkg_db_iter_new();
+  while ((pkg = pkg_db_iter_next(it)) != NULL) {
     ensure_package_clientdata(pkg);
     pkg->clientdata->istobe= itb_normal;
     pkg->clientdata->replacingfilesandsaid= 0;
   }
-  iterpkgend(it);
+  pkg_db_iter_free(it);
 }
 
 void debug(int which, const char *fmt, ...) {

+ 1 - 1
src/main.c

@@ -285,7 +285,7 @@ static void ignoredepends(const struct cmdinfo *cip, const char *value) {
     if (pnerr) ohshite(_("--ignore-depends requires a legal package name. "
                        "`%.250s' is not; %s"), p, pnerr);
 
-    pkg_list_prepend(&ignoredependss, findpackage(p));
+    pkg_list_prepend(&ignoredependss, pkg_db_find(p));
 
     p+= strlen(p)+1;
   }

+ 4 - 4
src/packages.c

@@ -60,8 +60,8 @@ enqueue_pending(void)
   struct pkgiterator *it;
   struct pkginfo *pkg;
 
-  it = iterpkgstart();
-  while ((pkg = iterpkgnext(it)) != NULL) {
+  it = pkg_db_iter_new();
+  while ((pkg = pkg_db_iter_next(it)) != NULL) {
     switch (cipaction->arg) {
     case act_configure:
       if (!(pkg->status == stat_unpacked ||
@@ -93,7 +93,7 @@ enqueue_pending(void)
     }
     add_to_queue(pkg);
   }
-  iterpkgend(it);
+  pkg_db_iter_free(it);
 }
 
 static void
@@ -104,7 +104,7 @@ enqueue_specified(const char *const *argv)
   while ((thisarg = *argv++) != NULL) {
     struct pkginfo *pkg;
 
-    pkg = findpackage(thisarg);
+    pkg = pkg_db_find(thisarg);
     if (pkg->status == stat_notinstalled) {
       size_t l = strlen(pkg->name);
       const char *extension = pkg->name + l - sizeof(DEBEXT) + 1;

+ 3 - 3
src/processarc.c

@@ -1029,8 +1029,8 @@ void process_archive(const char *filename) {
    * Conffiles are ignored (the new package had better do something
    * with them !).
    */
-  it= iterpkgstart();
-  while ((otherpkg = iterpkgnext(it)) != NULL) {
+  it = pkg_db_iter_new();
+  while ((otherpkg = pkg_db_iter_next(it)) != NULL) {
     ensure_package_clientdata(otherpkg);
     if (otherpkg == pkg ||
         otherpkg->status == stat_notinstalled ||
@@ -1149,7 +1149,7 @@ void process_archive(const char *filename) {
     modstatdb_note(otherpkg);
 
   } /* while (otherpkg= ... */
-  iterpkgend(it);
+  pkg_db_iter_free(it);
   
   /* Delete files from any other packages' lists.
    * We have to do this before we claim this package is in any

+ 2 - 2
src/querycmd.c

@@ -322,7 +322,7 @@ enqperpackage(const char *const *argv)
     modstatdb_init(admindir,msdbrw_readonly);
 
   while ((thisarg = *argv++) != NULL) {
-    pkg= findpackage(thisarg);
+    pkg = pkg_db_find(thisarg);
 
     switch (cipaction->arg) {
       
@@ -574,7 +574,7 @@ control_path(const char *const *argv)
 
   modstatdb_init(admindir, msdbrw_readonly | msdbrw_noavail);
 
-  pkg = findpackage(pkg_name);
+  pkg = pkg_db_find(pkg_name);
   if (pkg->status == stat_notinstalled)
     badusage(_("Package `%s' is not installed.\n"), pkg->name);
 

+ 4 - 4
src/select.c

@@ -129,7 +129,7 @@ void setselections(const char *const *argv) {
     if (e) ohshit(_("illegal package name at line %d: %.250s"),lno,e);
     for (nvp=wantinfos; nvp->name && strcmp(nvp->name,selvb.buf); nvp++);
     if (!nvp->name) ohshit(_("unknown wanted status at line %d: %.250s"),lno,selvb.buf);
-    pkg= findpackage(namevb.buf);
+    pkg = pkg_db_find(namevb.buf);
     pkg->want= nvp->value;
     if (c == EOF) break;
     lno++;
@@ -150,12 +150,12 @@ void clearselections(const char *const *argv)
 
   modstatdb_init(admindir, msdbrw_write);
 
-  it = iterpkgstart();
-  while ((pkg = iterpkgnext(it))) {
+  it = pkg_db_iter_new();
+  while ((pkg = pkg_db_iter_next(it))) {
     if (!pkg->installed.essential)
       pkg->want = want_deinstall;
   }
-  iterpkgend(it);
+  pkg_db_iter_free(it);
 
   modstatdb_shutdown();
 }

+ 7 - 7
src/trigproc.c

@@ -178,8 +178,8 @@ check_trigger_cycle(struct pkginfo *processing_now)
 	tcn->pkgs = NULL;
 	tcn->then_processed = processing_now;
 
-	it = iterpkgstart();
-	while ((pkg = iterpkgnext(it))) {
+	it = pkg_db_iter_new();
+	while ((pkg = pkg_db_iter_next(it))) {
 		if (!pkg->trigpend_head)
 			continue;
 		tcpp = nfmalloc(sizeof(*tcpp));
@@ -188,7 +188,7 @@ check_trigger_cycle(struct pkginfo *processing_now)
 		tcpp->next = tcn->pkgs;
 		tcn->pkgs = tcpp;
 	}
-	iterpkgend(it);
+	pkg_db_iter_free(it);
 	if (!hare) {
 		debug(dbg_triggersdetail, "check_triggers_cycle pnow=%s first",
 		      processing_now->name);
@@ -368,9 +368,8 @@ trig_transitional_activate(enum modstatdb_rw cstatus)
 	struct pkgiterator *it;
 	struct pkginfo *pkg;
 
-	it = iterpkgstart();
-
-	while ((pkg = iterpkgnext(it))) {
+	it = pkg_db_iter_new();
+	while ((pkg = pkg_db_iter_next(it))) {
 		if (pkg->status <= stat_halfinstalled)
 			continue;
 		debug(dbg_triggersdetail, "trig_transitional_activate %s %s",
@@ -381,7 +380,8 @@ trig_transitional_activate(enum modstatdb_rw cstatus)
 		              transitional_interest_callback :
 		              transitional_interest_callback_ro, NULL, pkg);
 	}
-	iterpkgend(it);
+	pkg_db_iter_free(it);
+
 	if (cstatus >= msdbrw_write) {
 		modstatdb_checkpoint();
 		trig_file_interests_save();