Просмотр исходного кода

Centralize warn counting in warningv()

Add an accessor function to be able to replace the old warn counters
in the rest of the code.
Guillem Jover лет назад: 15
Родитель
Сommit
8451065cf8

+ 5 - 14
dpkg-deb/build.c

@@ -216,7 +216,7 @@ check_file_perms(const char *dir)
 /**
  * Check if conffiles contains sane information.
  */
-static int
+static void
 check_conffiles(const char *dir)
 {
   FILE *cf;
@@ -224,14 +224,13 @@ check_conffiles(const char *dir)
   char conffilename[MAXCONFFILENAME + 1];
   struct file_info *conffiles_head = NULL;
   struct file_info *conffiles_tail = NULL;
-  int warns = 0;
 
   varbufprintf(&controlfile, "%s/%s/%s", dir, BUILDCONTROLDIR, CONFFILESFILE);
 
   cf = fopen(controlfile.buf, "r");
   if (cf == NULL) {
     if (errno == ENOENT)
-      return warns;
+      return;
 
     ohshite(_("error opening conffiles file"));
   }
@@ -249,7 +248,6 @@ check_conffiles(const char *dir)
 
       warning(_("conffile name '%.50s...' is too long, or missing final newline"),
               conffilename);
-      warns++;
       while ((c = getc(cf)) != EOF && c != '\n');
 
       continue;
@@ -268,12 +266,10 @@ check_conffiles(const char *dir)
         ohshite(_("conffile `%.250s' is not stattable"), conffilename);
     } else if (!S_ISREG(controlstab.st_mode)) {
       warning(_("conffile '%s' is not a plain file"), conffilename);
-      warns++;
     }
 
     if (file_info_find_name(conffiles_head, conffilename)) {
       warning(_("conffile name '%s' is duplicated"), conffilename);
-      warns++;
     } else {
       struct file_info *conffile;
 
@@ -288,8 +284,6 @@ check_conffiles(const char *dir)
   if (ferror(cf))
     ohshite(_("error reading conffiles file"));
   fclose(cf);
-
-  return warns;
 }
 
 static const char *arbitrary_fields[] = {
@@ -375,17 +369,14 @@ void do_build(const char *const *argv) {
 
     /* Let's start by reading in the control-file so we can check its
      * contents. */
-    warns = 0;
     varbufprintf(&controlfile, "%s/%s/%s", dir, BUILDCONTROLDIR, CONTROLFILE);
-    parsedb(controlfile.buf, pdb_recordavailable | pdb_rejectstatus,
-            &pkg, &warns);
+    parsedb(controlfile.buf, pdb_recordavailable | pdb_rejectstatus, &pkg);
     if (strspn(pkg->name, "abcdefghijklmnopqrstuvwxyz0123456789+-.") !=
         strlen(pkg->name))
       ohshit(_("package name has characters that aren't lowercase alphanums or `-+.'"));
     if (pkg->priority == pri_other) {
       warning(_("'%s' contains user-defined Priority value '%s'"),
               controlfile.buf, pkg->otherpriority);
-      warns++;
     }
     for (field = pkg->available.arbs; field; field = field->next) {
       if (known_arbitrary_field(field))
@@ -393,7 +384,6 @@ void do_build(const char *const *argv) {
 
       warning(_("'%s' contains user-defined field '%s'"),
               controlfile.buf, field->name);
-      warns++;
     }
 
     if (subdir) {
@@ -411,8 +401,9 @@ void do_build(const char *const *argv) {
     printf(_("dpkg-deb: building package `%s' in `%s'.\n"), pkg->name, debar);
 
     check_file_perms(dir);
-    warns += check_conffiles(dir);
+    check_conffiles(dir);
 
+    warns = warning_get_count();
     if (warns)
       warning(P_("ignoring %d warning about the control file(s)\n",
                  "ignoring %d warnings about the control file(s)\n", warns),

+ 1 - 1
dpkg-deb/info.c

@@ -264,7 +264,7 @@ void do_showinfo(const char* const* argv) {
   info_prepare(&argv, &debar, &dir, 1);
 
   parsedb(CONTROLFILE, pdb_recordavailable | pdb_rejectstatus | pdb_ignorefiles,
-          &pkg, NULL);
+          &pkg);
   pkg_format_show(fmt, pkg, &pkg->available);
 }
 

+ 3 - 3
lib/dpkg/dbmodify.c

@@ -75,7 +75,7 @@ static void cleanupdates(void) {
   struct dirent **cdlist;
   int cdn, i;
 
-  parsedb(statusfile, pdb_lax_parser | pdb_weakclassification, NULL, NULL);
+  parsedb(statusfile, pdb_lax_parser | pdb_weakclassification, NULL);
 
   *updatefnrest = '\0';
   updateslength= -1;
@@ -86,7 +86,7 @@ static void cleanupdates(void) {
     for (i=0; i<cdn; i++) {
       strcpy(updatefnrest, cdlist[i]->d_name);
       parsedb(updatefnbuf, pdb_lax_parser | pdb_weakclassification,
-              NULL, NULL);
+              NULL);
       if (cstatus < msdbrw_write) free(cdlist[i]);
     }
 
@@ -252,7 +252,7 @@ modstatdb_init(const char *admindir, enum modstatdb_rw readwritereq)
     if(!(cflags & msdbrw_noavail))
     parsedb(availablefile,
             pdb_recordavailable | pdb_rejectstatus | pdb_lax_parser,
-            NULL, NULL);
+            NULL);
   }
 
   if (cstatus >= msdbrw_write) {

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

@@ -256,8 +256,7 @@ enum parsedbflags {
 };
 
 const char *pkg_name_is_illegal(const char *p, const char **ep);
-int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep,
-            int *warncount);
+int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep);
 void copy_dependency_links(struct pkginfo *pkg,
                            struct dependency **updateme,
                            struct dependency *newdepends,

+ 9 - 0
lib/dpkg/ehandle.c

@@ -373,11 +373,20 @@ void ohshite(const char *fmt, ...) {
   run_error_handler();
 }
 
+static int warn_count = 0;
+
+int
+warning_get_count(void)
+{
+  return warn_count;
+}
+
 void
 warningv(const char *fmt, va_list args)
 {
   char buf[1024];
 
+  warn_count++;
   vsnprintf(buf, sizeof(buf), fmt, args);
   fprintf(stderr, _("%s: warning: %s\n"), thisname, buf);
 }

+ 1 - 0
lib/dpkg/ehandle.h

@@ -60,6 +60,7 @@ void push_cleanup(void (*f1)(int argc, void **argv), int flagmask1,
 void push_checkpoint(int mask, int value);
 void pop_cleanup(int flagset);
 
+int warning_get_count(void);
 void warningv(const char *fmt, va_list args) DPKG_ATTR_VPRINTF(1);
 void warning(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
 

+ 1 - 0
lib/dpkg/libdpkg.Versions

@@ -24,6 +24,7 @@ LIBDPKG_PRIVATE {
 	ohshit;
 	werr;			# XXX: remove
 	do_internerr;
+	warning_get_count;
 	warningv;
 	warning;
 

+ 1 - 5
lib/dpkg/parse.c

@@ -90,7 +90,7 @@ const struct fieldinfo fieldinfos[]= {
  * If donep is not NULL only one package's information is expected.
  */
 int parsedb(const char *filename, enum parsedbflags flags,
-            struct pkginfo **donep, int *warncount)
+            struct pkginfo **donep)
 {
   static int fd;
   struct pkginfo newpig, *pigp;
@@ -112,7 +112,6 @@ int parsedb(const char *filename, enum parsedbflags flags,
   ps.filename = filename;
   ps.flags = flags;
   ps.lno = 0;
-  ps.warncount = 0;
 
   newpifp= (flags & pdb_recordavailable) ? &newpig.available : &newpig.installed;
   fd= open(filename, O_RDONLY);
@@ -404,9 +403,6 @@ int parsedb(const char *filename, enum parsedbflags flags,
   if (close(fd)) ohshite(_("failed to close after read: `%.255s'"),filename);
   if (donep && !pdone) ohshit(_("no package information in `%.255s'"),filename);
 
-  if (warncount)
-    *warncount = ps.warncount;
-
   return pdone;
 }
 

+ 0 - 1
lib/dpkg/parsedump.h

@@ -28,7 +28,6 @@ struct parsedb_state {
 	enum parsedbflags flags;
 	const char *filename;
 	int lno;
-	int warncount;
 };
 
 #define PKGIFPOFF(f) (offsetof(struct pkginfoperfile, f))

+ 0 - 1
lib/dpkg/parsehelp.c

@@ -68,7 +68,6 @@ parse_warn(struct parsedb_state *ps,
   va_list args;
 
   va_start(args, fmt);
-  ps->warncount++;
   warningv(parse_error_msg(ps, pigp, fmt), args);
   va_end(args);
 }

+ 1 - 1
src/processarc.c

@@ -240,7 +240,7 @@ void process_archive(const char *filename) {
   strcpy(cidirrest,CONTROLFILE);
 
   parsedb(cidir, pdb_recordavailable | pdb_rejectstatus | pdb_ignorefiles,
-          &pkg, NULL);
+          &pkg);
   if (!pkg->files) {
     pkg->files= nfmalloc(sizeof(struct filedetails));
     pkg->files->next = NULL;

+ 2 - 2
src/update.c

@@ -80,12 +80,12 @@ void updateavailable(const char *const *argv) {
 
   if (cipaction->arg == act_avmerge)
     parsedb(vb.buf, pdb_recordavailable | pdb_rejectstatus | pdb_lax_parser,
-            NULL, NULL);
+            NULL);
 
   if (cipaction->arg != act_avclear)
     count += parsedb(sourcefile,
 		     pdb_recordavailable | pdb_rejectstatus | pdb_ignoreolder,
-                     NULL, NULL);
+                     NULL);
 
   if (!f_noact) {
     writedb(vb.buf,1,0);