Sfoglia il codice sorgente

dpkg: Normalize instdir by removing trailing '/' and '/.'

This gets rid of several inconsistencies and doubled «/» in syscalls
and output messages.
Guillem Jover 12 anni fa
parent
commit
f524ee7c6d
5 ha cambiato i file con 22 aggiunte e 17 eliminazioni
  1. 3 0
      debian/changelog
  2. 3 11
      src/archives.c
  3. 0 2
      src/configure.c
  4. 16 3
      src/main.c
  5. 0 1
      src/unpack.c

+ 3 - 0
debian/changelog

@@ -83,6 +83,9 @@ dpkg (1.17.14) UNRELEASED; urgency=low
       the Build-Profiles field in binary packages which can be removed once
       the Build-Profiles field in binary packages which can be removed once
       all affected source packages have moved to the new syntax.
       all affected source packages have moved to the new syntax.
     Thanks to Johannes Schauer <j.schauer@email.de>. Closes: #760158
     Thanks to Johannes Schauer <j.schauer@email.de>. Closes: #760158
+  * Normalize instdir in dpkg by removing trailing «/» and «/.». This gets
+    rid of several inconsistencies and doubled «/» in syscalls and output
+    messages.
 
 
   [ Raphaël Hertzog ]
   [ Raphaël Hertzog ]
   * Explain better in deb-triggers(5) why interest/activate-noawait should be
   * Explain better in deb-triggers(5) why interest/activate-noawait should be

+ 3 - 11
src/archives.c

@@ -390,7 +390,6 @@ tarobject_extract(struct tarcontext *tc, struct tar_entry *te,
   case TAR_FILETYPE_HARDLINK:
   case TAR_FILETYPE_HARDLINK:
     varbuf_reset(&hardlinkfn);
     varbuf_reset(&hardlinkfn);
     varbuf_add_str(&hardlinkfn, instdir);
     varbuf_add_str(&hardlinkfn, instdir);
-    varbuf_add_char(&hardlinkfn, '/');
     linknode = findnamenode(te->linkname, 0);
     linknode = findnamenode(te->linkname, 0);
     varbuf_add_str(&hardlinkfn,
     varbuf_add_str(&hardlinkfn,
                    namenodetouse(linknode, tc->pkg, &tc->pkg->available)->name);
                    namenodetouse(linknode, tc->pkg, &tc->pkg->available)->name);
@@ -832,7 +831,7 @@ tarobject(void *ctx, struct tar_entry *ti)
     st = &ti->stat;
     st = &ti->stat;
 
 
   usenode = namenodetouse(nifd->namenode, tc->pkg, &tc->pkg->available);
   usenode = namenodetouse(nifd->namenode, tc->pkg, &tc->pkg->available);
-  usename = usenode->name + 1; /* Skip the leading '/'. */
+  usename = usenode->name;
 
 
   trig_file_activate(usenode, tc->pkg);
   trig_file_activate(usenode, tc->pkg);
 
 
@@ -1196,16 +1195,14 @@ tar_writeback_barrier(struct fileinlist *files, struct pkginfo *pkg)
 
 
   for (cfile = files; cfile; cfile = cfile->next) {
   for (cfile = files; cfile; cfile = cfile->next) {
     struct filenamenode *usenode;
     struct filenamenode *usenode;
-    const char *usename;
     int fd;
     int fd;
 
 
     if (!(cfile->namenode->flags & fnnf_deferred_fsync))
     if (!(cfile->namenode->flags & fnnf_deferred_fsync))
       continue;
       continue;
 
 
     usenode = namenodetouse(cfile->namenode, pkg, &pkg->available);
     usenode = namenodetouse(cfile->namenode, pkg, &pkg->available);
-    usename = usenode->name + 1; /* Skip the leading '/'. */
 
 
-    setupfnamevbs(usename);
+    setupfnamevbs(usenode->name);
 
 
     fd = open(fnamenewvb.buf, O_WRONLY);
     fd = open(fnamenewvb.buf, O_WRONLY);
     if (fd < 0)
     if (fd < 0)
@@ -1230,7 +1227,6 @@ tar_deferred_extract(struct fileinlist *files, struct pkginfo *pkg)
 {
 {
   struct fileinlist *cfile;
   struct fileinlist *cfile;
   struct filenamenode *usenode;
   struct filenamenode *usenode;
-  const char *usename;
 
 
   tar_writeback_barrier(files, pkg);
   tar_writeback_barrier(files, pkg);
 
 
@@ -1241,9 +1237,8 @@ tar_deferred_extract(struct fileinlist *files, struct pkginfo *pkg)
       continue;
       continue;
 
 
     usenode = namenodetouse(cfile->namenode, pkg, &pkg->available);
     usenode = namenodetouse(cfile->namenode, pkg, &pkg->available);
-    usename = usenode->name + 1; /* Skip the leading '/'. */
 
 
-    setupfnamevbs(usename);
+    setupfnamevbs(usenode->name);
 
 
     if (cfile->namenode->flags & fnnf_deferred_fsync) {
     if (cfile->namenode->flags & fnnf_deferred_fsync) {
       int fd;
       int fd;
@@ -1646,11 +1641,8 @@ archivefiles(const char *const *argv)
   varbuf_reset(&fnamenewvb);
   varbuf_reset(&fnamenewvb);
 
 
   varbuf_add_str(&fnamevb, instdir);
   varbuf_add_str(&fnamevb, instdir);
-  varbuf_add_char(&fnamevb, '/');
   varbuf_add_str(&fnametmpvb, instdir);
   varbuf_add_str(&fnametmpvb, instdir);
-  varbuf_add_char(&fnametmpvb, '/');
   varbuf_add_str(&fnamenewvb, instdir);
   varbuf_add_str(&fnamenewvb, instdir);
-  varbuf_add_char(&fnamenewvb, '/');
   fnameidlu= fnamevb.used;
   fnameidlu= fnamevb.used;
 
 
   ensure_diversions();
   ensure_diversions();

+ 0 - 2
src/configure.c

@@ -716,8 +716,6 @@ conffderef(struct pkginfo *pkg, struct varbuf *result, const char *in)
 
 
 	varbuf_reset(result);
 	varbuf_reset(result);
 	varbuf_add_str(result, instdir);
 	varbuf_add_str(result, instdir);
-	if (*in != '/')
-		varbuf_add_char(result, '/');
 	varbuf_add_str(result, in);
 	varbuf_add_str(result, in);
 	varbuf_end_str(result);
 	varbuf_end_str(result);
 
 

+ 16 - 3
src/main.c

@@ -46,6 +46,7 @@
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
 #include <dpkg/dpkg-db.h>
 #include <dpkg/arch.h>
 #include <dpkg/arch.h>
+#include <dpkg/path.h>
 #include <dpkg/subproc.h>
 #include <dpkg/subproc.h>
 #include <dpkg/command.h>
 #include <dpkg/command.h>
 #include <dpkg/options.h>
 #include <dpkg/options.h>
@@ -343,12 +344,24 @@ set_verify_format(const struct cmdinfo *cip, const char *value)
     badusage(_("unknown verify output format '%s'"), value);
     badusage(_("unknown verify output format '%s'"), value);
 }
 }
 
 
+static void
+set_instdir(const struct cmdinfo *cip, const char *value)
+{
+  char *new_instdir;
+
+  new_instdir = m_strdup(value);
+  path_trim_slash_slashdot(new_instdir);
+
+  instdir = new_instdir;
+}
+
 static void
 static void
 set_root(const struct cmdinfo *cip, const char *value)
 set_root(const struct cmdinfo *cip, const char *value)
 {
 {
   char *p;
   char *p;
-  instdir= value;
-  m_asprintf(&p, "%s%s", value, ADMINDIR);
+
+  set_instdir(cip, value);
+  m_asprintf(&p, "%s%s", instdir, ADMINDIR);
   admindir= p;
   admindir= p;
 }
 }
 
 
@@ -710,7 +723,7 @@ static const struct cmdinfo cmdinfos[]= {
   { "root",              0,   1, NULL,          NULL,      set_root,      0 },
   { "root",              0,   1, NULL,          NULL,      set_root,      0 },
   { "abort-after",       0,   1, &errabort,     NULL,      set_integer,   0 },
   { "abort-after",       0,   1, &errabort,     NULL,      set_integer,   0 },
   { "admindir",          0,   1, NULL,          &admindir, NULL,          0 },
   { "admindir",          0,   1, NULL,          &admindir, NULL,          0 },
-  { "instdir",           0,   1, NULL,          &instdir,  NULL,          0 },
+  { "instdir",           0,   1, NULL,          NULL,      set_instdir,   0 },
   { "ignore-depends",    0,   1, NULL,          NULL,      set_ignore_depends, 0 },
   { "ignore-depends",    0,   1, NULL,          NULL,      set_ignore_depends, 0 },
   { "force",             0,   2, NULL,          NULL,      set_force,     1 },
   { "force",             0,   2, NULL,          NULL,      set_force,     1 },
   { "refuse",            0,   2, NULL,          NULL,      set_force,     0 },
   { "refuse",            0,   2, NULL,          NULL,      set_force,     0 },

+ 0 - 1
src/unpack.c

@@ -1084,7 +1084,6 @@ void process_archive(const char *filename) {
 
 
 	  varbuf_reset(&cfilename);
 	  varbuf_reset(&cfilename);
 	  varbuf_add_str(&cfilename, instdir);
 	  varbuf_add_str(&cfilename, instdir);
-	  varbuf_add_char(&cfilename, '/');
 	  varbuf_add_str(&cfilename, cfile->namenode->name);
 	  varbuf_add_str(&cfilename, cfile->namenode->name);
 	  varbuf_end_str(&cfilename);
 	  varbuf_end_str(&cfilename);