summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2011-02-26 18:02:05 +0100
committerGuillem Jover <guillem@debian.org>2011-03-02 07:35:00 +0100
commitfc8b6ecf05e6d4bc66e036f275daa304ada6696e (patch)
treee56f3424b2d9d36348ab25861f83c752c8bc203a
parentecd886da6390f9c10b8a36d27323f0bc570e97f3 (diff)
downloaddpkg-fc8b6ecf05e6d4bc66e036f275daa304ada6696e.tar.gz
dpkg: Refactor specific infodb traversal logic into their own functions
This will allow further refactoring now that the infodb traversal code is the same eveyrwhere.
-rw-r--r--src/processarc.c55
-rw-r--r--src/querycmd.c35
-rw-r--r--src/remove.c28
3 files changed, 76 insertions, 42 deletions
diff --git a/src/processarc.c b/src/processarc.c
index 41512581e..c59cb4bed 100644
--- a/src/processarc.c
+++ b/src/processarc.c
@@ -172,6 +172,8 @@ struct match_node {
char *filename;
};
+static struct match_node *match_head = NULL;
+
static struct match_node *
match_node_new(const char *name, const char *type, struct match_node *next)
{
@@ -193,6 +195,33 @@ match_node_free(struct match_node *node)
free(node);
}
+static void
+pkg_infodb_update_file(const char *filename, const char *filetype)
+{
+ if (strlen(filetype) > MAXCONTROLFILENAME)
+ ohshit(_("old version of package has overly-long info file name starting `%.250s'"),
+ filename);
+
+ /* We do the list separately. */
+ if (strcmp(filetype, LISTFILE) == 0)
+ return;
+
+ /* We keep files to rename in a list as doing the rename immediately
+ * might influence the current readdir(), the just renamed file might
+ * be returned a second time as it's actually a new file from the
+ * point of view of the filesystem. */
+ match_head = match_node_new(filename, filetype, match_head);
+}
+
+static void
+pkg_infodb_remove_file(const char *filename, const char *filetype)
+{
+ if (unlink(filename))
+ ohshite(_("unable to delete control info file `%.250s'"), filename);
+
+ debug(dbg_scripts, "removal_bulk info unlinked %s", filename);
+}
+
void process_archive(const char *filename) {
static const struct tar_operations tf = {
.read = tarfileread,
@@ -235,7 +264,7 @@ void process_archive(const char *filename) {
struct dirent *de;
struct stat stab, oldfs;
struct pkg_deconf_list *deconpil, *deconpiltemp;
- struct match_node *match_head = NULL, *match_node = NULL;
+ struct match_node *match_node;
cleanup_pkg_failed= cleanup_conflictor_failed= 0;
@@ -896,6 +925,12 @@ void process_archive(const char *filename) {
* them as appropriate; then we go through the new scripts
* (any that are left) and install them. */
debug(dbg_general, "process_archive updating info directory");
+
+ /* Deallocate the match list in case we aborted previously. */
+ while ((match_node = match_head)) {
+ match_head = match_node->next;
+ match_node_free(match_node);
+ }
varbuf_reset(&infofnvb);
varbuf_add_str(&infofnvb, pkgadmindir());
infodirlen= infofnvb.used;
@@ -920,21 +955,12 @@ void process_archive(const char *filename) {
/* Skip past the full stop. */
p++;
- /* We do the list separately. */
- if (!strcmp(p, LISTFILE))
- continue;
- if (strlen(p) > MAXCONTROLFILENAME)
- ohshit(_("old version of package has overly-long info file name starting `%.250s'"),
- de->d_name);
+
varbuf_trunc(&infofnvb, infodirlen);
varbuf_add_str(&infofnvb, de->d_name);
varbuf_end_str(&infofnvb);
- /* We keep files to rename in a list as doing the rename immediately
- * might influence the current readdir(), the just renamed file might
- * be returned a second time as it's actually a new file from the
- * point of view of the filesystem. */
- match_head = match_node_new(infofnvb.buf, p, match_head);
+ pkg_infodb_update_file(infofnvb.buf, p);
}
pop_cleanup(ehflag_normaltidy); /* closedir */
@@ -1188,9 +1214,8 @@ void process_archive(const char *filename) {
varbuf_trunc(&fnvb, infodirbaseused);
varbuf_add_str(&fnvb, de->d_name);
varbuf_end_str(&fnvb);
- if (unlink(fnvb.buf))
- ohshite(_("unable to delete disappearing control info file `%.250s'"),fnvb.buf);
- debug(dbg_scripts, "process_archive info unlinked %s",fnvb.buf);
+
+ pkg_infodb_remove_file(fnvb.buf, p + 1);
}
pop_cleanup(ehflag_normaltidy); /* closedir */
diff --git a/src/querycmd.c b/src/querycmd.c
index a3cc07814..d164cb7ce 100644
--- a/src/querycmd.c
+++ b/src/querycmd.c
@@ -4,7 +4,7 @@
*
* Copyright © 1995,1996 Ian Jackson <ian@chiark.greenend.org.uk>
* Copyright © 2000,2001 Wichert Akkerman <wakkerma@debian.org>
- * Copyright © 2006-2009 Guillem Jover <guillem@debian.org>
+ * Copyright © 2006-2011 Guillem Jover <guillem@debian.org>
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -515,25 +515,32 @@ showpackages(const char *const *argv)
}
static void
+pkg_infodb_print_filename(const char *filename, const char *filetype)
+{
+ /* Do not expose internal database files. */
+ if (strcmp(filetype, LISTFILE) == 0 ||
+ strcmp(filetype, CONFFILESFILE) == 0)
+ return;
+
+ if (strlen(filetype) > MAXCONTROLFILENAME)
+ return;
+
+ printf("%s\n", filename);
+}
+
+static void
control_path_file(struct pkginfo *pkg, const char *control_file)
{
const char *control_path;
struct stat st;
- /* Do not expose internal database files. */
- if (strcmp(control_file, LISTFILE) == 0 ||
- strcmp(control_file, CONFFILESFILE) == 0)
- return;
-
control_path = pkgadminfile(pkg, control_file);
-
if (stat(control_path, &st) < 0)
return;
-
if (!S_ISREG(st.st_mode))
return;
- printf("%s\n", control_path);
+ pkg_infodb_print_filename(control_path, control_file);
}
static void
@@ -574,19 +581,11 @@ control_path_pkg(struct pkginfo *pkg)
/* Skip past the full stop. */
p++;
- /* Do not expose internal database files. */
- if (strcmp(p, LISTFILE) == 0 ||
- strcmp(p, CONFFILESFILE) == 0)
- continue;
-
- if (strlen(p) > MAXCONTROLFILENAME)
- continue;
-
varbuf_trunc(&db_path, db_path_len);
varbuf_add_str(&db_path, db_de->d_name);
varbuf_end_str(&db_path);
- printf("%s\n", db_path.buf);
+ pkg_infodb_print_filename(db_path.buf, p);
}
pop_cleanup(ehflag_normaltidy); /* closedir */
diff --git a/src/remove.c b/src/remove.c
index 00dedad1f..0b5bb8121 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -185,6 +185,22 @@ static void push_leftover(struct fileinlist **leftoverp,
}
static void
+removal_bulk_remove_file(const char *filename, const char *filetype)
+{
+ /* We need the postrm and list files for --purge. */
+ if (strcmp(filetype, LISTFILE) == 0 ||
+ strcmp(filetype, POSTRMFILE) == 0)
+ return;
+
+ debug(dbg_stupidlyverbose, "removal_bulk info not postrm or list");
+
+ if (unlink(filename))
+ ohshite(_("unable to delete control info file `%.250s'"), filename);
+
+ debug(dbg_scripts, "removal_bulk info unlinked %s", filename);
+}
+
+static void
removal_bulk_remove_files(struct pkginfo *pkg)
{
int before;
@@ -291,18 +307,12 @@ removal_bulk_remove_files(struct pkginfo *pkg)
if (strlen(pkg->name) != (size_t)(p-de->d_name) ||
strncmp(de->d_name,pkg->name,p-de->d_name)) continue;
debug(dbg_stupidlyverbose, "removal_bulk info this pkg");
- /* We need the postrm and list files for --purge. */
- if (!strcmp(p+1,LISTFILE)) continue;
- if (!strcmp(p + 1, POSTRMFILE)) {
- continue;
- }
- debug(dbg_stupidlyverbose, "removal_bulk info not postrm or list");
+
varbuf_trunc(&fnvb, infodirbaseused);
varbuf_add_str(&fnvb, de->d_name);
varbuf_end_str(&fnvb);
- if (unlink(fnvb.buf))
- ohshite(_("unable to delete control info file `%.250s'"),fnvb.buf);
- debug(dbg_scripts, "removal_bulk info unlinked %s",fnvb.buf);
+
+ removal_bulk_remove_file(fnvb.buf, p + 1);
}
pop_cleanup(ehflag_normaltidy); /* closedir */