Explorar el Código

Use dpkg_db_get_path() instead of ad-hoc building the string with varbuf

Guillem Jover hace 15 años
padre
commit
8ecd3414eb
Se han modificado 3 ficheros con 22 adiciones y 26 borrados
  1. 9 11
      src/divertdb.c
  2. 7 9
      src/statdb.c
  3. 6 6
      src/update.c

+ 9 - 11
src/divertdb.c

@@ -42,25 +42,23 @@
 
 static struct diversion *diversions = NULL;
 static FILE *diversionsfile = NULL;
+static char *diversionsname;
 
 void
 ensure_diversions(void)
 {
-	static struct varbuf vb;
-
 	struct stat stab1, stab2;
 	char linebuf[MAXDIVERTFILENAME];
 	FILE *file;
 	struct diversion *ov, *oicontest, *oialtname;
 
-	varbuf_reset(&vb);
-	varbuf_add_str(&vb, admindir);
-	varbuf_add_str(&vb, "/" DIVERSIONSFILE);
-	varbuf_end_str(&vb);
+	if (diversionsname != NULL)
+		free(diversionsname);
+	diversionsname = dpkg_db_get_path(DIVERSIONSFILE);
 
 	onerr_abort++;
 
-	file = fopen(vb.buf,"r");
+	file = fopen(diversionsname, "r");
 	if (!file) {
 		if (errno != ENOENT)
 			ohshite(_("failed to open diversions file"));
@@ -83,7 +81,7 @@ ensure_diversions(void)
 	if (diversionsfile)
 		fclose(diversionsfile);
 	diversionsfile = file;
-	setcloexec(fileno(diversionsfile), vb.buf);
+	setcloexec(fileno(diversionsfile), diversionsname);
 
 	for (ov = diversions; ov; ov = ov->next) {
 		ov->useinstead->divert->camefrom->divert = NULL;
@@ -95,18 +93,18 @@ ensure_diversions(void)
 		return;
 	}
 
-	while (fgets_checked(linebuf, sizeof(linebuf), file, vb.buf) >= 0) {
+	while (fgets_checked(linebuf, sizeof(linebuf), file, diversionsname) >= 0) {
 		oicontest = nfmalloc(sizeof(struct diversion));
 		oialtname = nfmalloc(sizeof(struct diversion));
 
 		oialtname->camefrom = findnamenode(linebuf, 0);
 		oialtname->useinstead = NULL;
 
-		fgets_must(linebuf, sizeof(linebuf), file, vb.buf);
+		fgets_must(linebuf, sizeof(linebuf), file, diversionsname);
 		oicontest->useinstead = findnamenode(linebuf, 0);
 		oicontest->camefrom = NULL;
 
-		fgets_must(linebuf, sizeof(linebuf), file, vb.buf);
+		fgets_must(linebuf, sizeof(linebuf), file, diversionsname);
 		oicontest->pkg = oialtname->pkg = strcmp(linebuf, ":") ?
 		                                  pkg_db_find(linebuf) : NULL;
 

+ 7 - 9
src/statdb.c

@@ -43,6 +43,7 @@
 #include "main.h"
 
 static FILE *statoverridefile = NULL;
+static char *statoverridename;
 
 uid_t
 statdb_parse_uid(const char *str)
@@ -108,22 +109,19 @@ statdb_parse_mode(const char *str)
 void
 ensure_statoverrides(void)
 {
-	static struct varbuf vb;
-
 	struct stat stab1, stab2;
 	FILE *file;
 	char *loaded_list, *loaded_list_end, *thisline, *nextline, *ptr;
 	struct file_stat *fso;
 	struct filenamenode *fnn;
 
-	varbuf_reset(&vb);
-	varbuf_add_str(&vb, admindir);
-	varbuf_add_str(&vb, "/" STATOVERRIDEFILE);
-	varbuf_end_str(&vb);
+	if (statoverridename != NULL)
+		free(statoverridename);
+	statoverridename = dpkg_db_get_path(STATOVERRIDEFILE);
 
 	onerr_abort++;
 
-	file = fopen(vb.buf,"r");
+	file = fopen(statoverridename, "r");
 	if (!file) {
 		if (errno != ENOENT)
 			ohshite(_("failed to open statoverride file"));
@@ -148,7 +146,7 @@ ensure_statoverrides(void)
 	if (statoverridefile)
 		fclose(statoverridefile);
 	statoverridefile = file;
-	setcloexec(fileno(statoverridefile), vb.buf);
+	setcloexec(fileno(statoverridefile), statoverridename);
 
 	/* If the statoverride list is empty we don't need to bother
 	 * reading it. */
@@ -161,7 +159,7 @@ ensure_statoverrides(void)
 	loaded_list_end = loaded_list + stab2.st_size;
 
 	if (fd_read(fileno(file), loaded_list, stab2.st_size) < 0)
-		ohshite(_("reading statoverride file '%.250s'"), vb.buf);
+		ohshite(_("reading statoverride file '%.250s'"), statoverridename);
 
 	thisline = loaded_list;
 	while (thisline < loaded_list_end) {

+ 6 - 6
src/update.c

@@ -36,8 +36,8 @@
 
 void updateavailable(const char *const *argv) {
   const char *sourcefile= argv[0];
+  char *availfile;
   int count= 0;
-  static struct varbuf vb;
 
   modstatdb_init(admindir);
 
@@ -76,12 +76,10 @@ void updateavailable(const char *const *argv) {
     internerr("unknown action '%d'", cipaction->arg_int);
   }
 
-  varbuf_add_str(&vb, admindir);
-  varbuf_add_str(&vb, "/" AVAILFILE);
-  varbuf_end_str(&vb);
+  availfile = dpkg_db_get_path(AVAILFILE);
 
   if (cipaction->arg_int == act_avmerge)
-    parsedb(vb.buf, pdb_recordavailable | pdb_rejectstatus | pdb_lax_parser,
+    parsedb(availfile, pdb_recordavailable | pdb_rejectstatus | pdb_lax_parser,
             NULL);
 
   if (cipaction->arg_int != act_avclear)
@@ -90,10 +88,12 @@ void updateavailable(const char *const *argv) {
                      NULL);
 
   if (!f_noact) {
-    writedb(vb.buf,1,0);
+    writedb(availfile, 1, 0);
     modstatdb_unlock();
   }
 
+  free(availfile);
+
   if (cipaction->arg_int != act_avclear)
     printf(P_("Information about %d package was updated.\n",
               "Information about %d packages was updated.\n", count), count);