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

dpkg: Refactor conflictor addition to a new push_conflictor() function

Move the conflictor and cflict_index variables to processarc.c and
make them static. And create a new push_conflictor() function to hide
the implementation details. This fixes a warning on variable shadowing.
Guillem Jover лет назад: 15
Родитель
Сommit
0d6e7bc21e
3 измененных файлов с 16 добавлено и 12 удалено
  1. 1 10
      src/archives.c
  2. 1 2
      src/archives.h
  3. 14 0
      src/processarc.c

+ 1 - 10
src/archives.c

@@ -62,11 +62,6 @@
 #include "archives.h"
 #include "filters.h"
 
-#define MAXCONFLICTORS 20
-
-struct pkginfo *conflictor[MAXCONFLICTORS];
-int cflict_index = 0;
-
 static inline void
 fd_writeback_init(int fd)
 {
@@ -1146,12 +1141,8 @@ void check_conflict(struct dependency *dep, struct pkginfo *pkg,
         }
       }
       if (!pdep) {
-	if (cflict_index >= MAXCONFLICTORS)
-	  ohshit(_("package %s has too many Conflicts/Replaces pairs"),
-		 pkg->name);
-
         /* This conflict is OK - we'll remove the conflictor. */
-	conflictor[cflict_index++]= fixbyrm;
+        push_conflictor(pkg, fixbyrm);
         varbuf_destroy(&conflictwhy); varbuf_destroy(&removalwhy);
         fprintf(stderr, _("dpkg: yes, will remove %s in favour of %s.\n"),
                 fixbyrm->name, pkg->name);

+ 1 - 2
src/archives.h

@@ -41,8 +41,7 @@ extern struct varbuf fnametmpvb;
 extern struct varbuf fnamenewvb;
 extern struct pkg_deconf_list *deconfigure;
 
-extern struct pkginfo *conflictor[];
-extern int cflict_index;
+void push_conflictor(struct pkginfo *pkg, struct pkginfo *pkg_fixbyrm);
 
 void cu_pathname(int argc, void **argv);
 void cu_cidir(int argc, void **argv);

+ 14 - 0
src/processarc.c

@@ -157,6 +157,20 @@ deb_verify(const char *filename)
   }
 }
 
+#define MAXCONFLICTORS 20
+
+static struct pkginfo *conflictor[MAXCONFLICTORS];
+static int cflict_index = 0;
+
+void
+push_conflictor(struct pkginfo *pkg, struct pkginfo *pkg_fixbyrm)
+{
+  if (cflict_index >= MAXCONFLICTORS)
+    ohshit(_("package %s has too many Conflicts/Replaces pairs"), pkg->name);
+
+  conflictor[cflict_index++] = pkg_fixbyrm;
+}
+
 void process_archive(const char *filename) {
   static const struct tar_operations tf = {
     .read = tarfileread,