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

dpkg: Switch the rename_list logic to match_node

Instead of directly preparing the arguments on traversal, store the
information of the matched files, which we'll be acting on later in
the code. This will allow for further refactoring.
Guillem Jover лет назад: 15
Родитель
Сommit
070dc94cfc
1 измененных файлов с 27 добавлено и 24 удалено
  1. 27 24
      src/processarc.c

+ 27 - 24
src/processarc.c

@@ -3,6 +3,7 @@
  * processarc.c - the huge function process_archive
  * processarc.c - the huge function process_archive
  *
  *
  * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
+ * Copyright © 2006-2011 Guillem Jover <guillem@debian.org>
  *
  *
  * This is free software; you can redistribute it and/or modify
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * it under the terms of the GNU General Public License as published by
@@ -52,12 +53,6 @@
 #include "main.h"
 #include "main.h"
 #include "archives.h"
 #include "archives.h"
 
 
-struct rename_list {
-  struct rename_list *next;
-  char *src;
-  char *dst;
-};
-
 static const char *
 static const char *
 summarize_filename(const char *filename)
 summarize_filename(const char *filename)
 {
 {
@@ -171,6 +166,12 @@ push_conflictor(struct pkginfo *pkg, struct pkginfo *pkg_fixbyrm)
   conflictor[cflict_index++] = pkg_fixbyrm;
   conflictor[cflict_index++] = pkg_fixbyrm;
 }
 }
 
 
+struct match_node {
+  struct match_node *next;
+  char *filetype;
+  char *filename;
+};
+
 void process_archive(const char *filename) {
 void process_archive(const char *filename) {
   static const struct tar_operations tf = {
   static const struct tar_operations tf = {
     .read = tarfileread,
     .read = tarfileread,
@@ -213,7 +214,7 @@ void process_archive(const char *filename) {
   struct dirent *de;
   struct dirent *de;
   struct stat stab, oldfs;
   struct stat stab, oldfs;
   struct pkg_deconf_list *deconpil, *deconpiltemp;
   struct pkg_deconf_list *deconpil, *deconpiltemp;
-  struct rename_list *rename_head = NULL, *rename_node = NULL;
+  struct match_node *match_head = NULL, *match_node = NULL;
 
 
   cleanup_pkg_failed= cleanup_conflictor_failed= 0;
   cleanup_pkg_failed= cleanup_conflictor_failed= 0;
 
 
@@ -907,38 +908,40 @@ void process_archive(const char *filename) {
     varbuf_trunc(&infofnvb, infodirlen);
     varbuf_trunc(&infofnvb, infodirlen);
     varbuf_add_str(&infofnvb, de->d_name);
     varbuf_add_str(&infofnvb, de->d_name);
     varbuf_end_str(&infofnvb);
     varbuf_end_str(&infofnvb);
-    strcpy(cidirrest,p);
 
 
     /* We keep files to rename in a list as doing the rename immediately
     /* We keep files to rename in a list as doing the rename immediately
      * might influence the current readdir(), the just renamed file might
      * might influence the current readdir(), the just renamed file might
      * be returned a second time as it's actually a new file from the
      * be returned a second time as it's actually a new file from the
      * point of view of the filesystem. */
      * point of view of the filesystem. */
-    rename_node = m_malloc(sizeof(*rename_node));
-    rename_node->next = rename_head;
-    rename_node->src = m_strdup(cidir);
-    rename_node->dst = m_strdup(infofnvb.buf);
-    rename_head = rename_node;
+    match_node = m_malloc(sizeof(*match_node));
+    match_node->next = match_head;
+    match_node->filetype = m_strdup(p);
+    match_node->filename = m_strdup(infofnvb.buf);
+    match_head = match_node;
   }
   }
   pop_cleanup(ehflag_normaltidy); /* closedir */
   pop_cleanup(ehflag_normaltidy); /* closedir */
 
 
-  while ((rename_node = rename_head)) {
-    if (!rename(rename_node->src, rename_node->dst)) {
+  while ((match_node = match_head)) {
+    strcpy(cidirrest, match_node->filetype);
+
+    if (!rename(cidir, match_node->filename)) {
       debug(dbg_scripts, "process_archive info installed %s as %s",
       debug(dbg_scripts, "process_archive info installed %s as %s",
-            rename_node->src, rename_node->dst);
+            cidir, match_node->filename);
     } else if (errno == ENOENT) {
     } else if (errno == ENOENT) {
       /* Right, no new version. */
       /* Right, no new version. */
-      if (unlink(rename_node->dst))
+      if (unlink(match_node->filename))
         ohshite(_("unable to remove obsolete info file `%.250s'"),
         ohshite(_("unable to remove obsolete info file `%.250s'"),
-                rename_node->dst);
-      debug(dbg_scripts, "process_archive info unlinked %s", rename_node->dst);
+                match_node->filename);
+      debug(dbg_scripts, "process_archive info unlinked %s",
+            match_node->filename);
     } else {
     } else {
       ohshite(_("unable to install (supposed) new info file `%.250s'"),
       ohshite(_("unable to install (supposed) new info file `%.250s'"),
-              rename_node->src);
+              cidir);
     }
     }
-    rename_head = rename_node->next;
-    free(rename_node->src);
-    free(rename_node->dst);
-    free(rename_node);
+    match_head = match_node->next;
+    free(match_node->filetype);
+    free(match_node->filename);
+    free(match_node);
   }
   }
 
 
   /* The directory itself. */
   /* The directory itself. */