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

Rename directory variables to just dir

The shorter form is unambiguous and takes less screen size.
Guillem Jover лет назад: 15
Родитель
Сommit
06f0675ffa
5 измененных файлов с 78 добавлено и 63 удалено
  1. 18 15
      dpkg-deb/build.c
  2. 1 1
      dpkg-deb/dpkg-deb.h
  3. 16 10
      dpkg-deb/extract.c
  4. 36 30
      dpkg-deb/info.c
  5. 7 7
      src/archives.c

+ 18 - 15
dpkg-deb/build.c

@@ -205,7 +205,7 @@ free_filist(struct file_info *fi)
  * Overly complex function that builds a .deb file.
  */
 void do_build(const char *const *argv) {
-  const char *debar, *directory;
+  const char *debar, *dir;
   bool subdir;
   char *tfbuf;
   FILE *ar;
@@ -216,8 +216,8 @@ void do_build(const char *const *argv) {
   struct file_info *symlist_end = NULL;
 
   /* Decode our arguments. */
-  directory = *argv++;
-  if (!directory)
+  dir = *argv++;
+  if (!dir)
     badusage(_("--%s needs a <directory> argument"), cipaction->olong);
   subdir = false;
   debar = *argv++;
@@ -236,8 +236,8 @@ void do_build(const char *const *argv) {
   } else {
     char *m;
 
-    m= m_malloc(strlen(directory) + sizeof(DEBEXT));
-    strcpy(m, directory);
+    m= m_malloc(strlen(dir) + sizeof(DEBEXT));
+    strcpy(m, dir);
     path_trim_slash_slashdot(m);
     strcat(m, DEBEXT);
     debar= m;
@@ -261,14 +261,14 @@ void do_build(const char *const *argv) {
     int warns;
     FILE *cf;
 
-    controlfile= m_malloc(strlen(directory) + sizeof(BUILDCONTROLDIR) +
+    controlfile= m_malloc(strlen(dir) + sizeof(BUILDCONTROLDIR) +
                           sizeof(CONTROLFILE) + sizeof(CONFFILESFILE) +
                           sizeof(POSTINSTFILE) + sizeof(PREINSTFILE) +
                           sizeof(POSTRMFILE) + sizeof(PRERMFILE) +
                           MAXCONFFILENAME + 5);
     /* Let's start by reading in the control-file so we can check its
      * contents. */
-    strcpy(controlfile, directory);
+    strcpy(controlfile, dir);
     strcat(controlfile, "/" BUILDCONTROLDIR "/" CONTROLFILE);
     warns = 0;
     parsedb(controlfile, pdb_recordavailable|pdb_rejectstatus,
@@ -306,7 +306,7 @@ void do_build(const char *const *argv) {
     printf(_("dpkg-deb: building package `%s' in `%s'.\n"), checkedinfo->name, debar);
 
     /* Check file permissions. */
-    strcpy(controlfile, directory);
+    strcpy(controlfile, dir);
     strcat(controlfile, "/" BUILDCONTROLDIR "/");
     if (lstat(controlfile, &mscriptstab))
       ohshite(_("unable to stat control directory"));
@@ -317,7 +317,7 @@ void do_build(const char *const *argv) {
              "and <=0775)"), (unsigned long)(mscriptstab.st_mode & 07777));
 
     for (mscriptp= maintainerscripts; *mscriptp; mscriptp++) {
-      strcpy(controlfile, directory);
+      strcpy(controlfile, dir);
       strcat(controlfile, "/" BUILDCONTROLDIR "/");
       strcat(controlfile, *mscriptp);
 
@@ -335,7 +335,7 @@ void do_build(const char *const *argv) {
     }
 
     /* Check if conffiles contains sane information. */
-    strcpy(controlfile, directory);
+    strcpy(controlfile, dir);
     strcat(controlfile, "/" BUILDCONTROLDIR "/" CONFFILESFILE);
     if ((cf= fopen(controlfile,"r"))) {
       char conffilename[MAXCONFFILENAME + 1];
@@ -358,7 +358,7 @@ void do_build(const char *const *argv) {
           continue;
         }
         conffilename[n - 1] = '\0';
-        strcpy(controlfile, directory);
+        strcpy(controlfile, dir);
         strcat(controlfile, "/");
         strcat(controlfile, conffilename);
         if (lstat(controlfile,&controlstab)) {
@@ -410,7 +410,8 @@ void do_build(const char *const *argv) {
   c1 = subproc_fork();
   if (!c1) {
     m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
-    if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory);
+    if (chdir(dir))
+      ohshite(_("failed to chdir to `%.255s'"), dir);
     if (chdir(BUILDCONTROLDIR))
       ohshite(_("failed to chdir to `%.255s'"), ".../DEBIAN");
     execlp(TAR, "tar", "-cf", "-", "--format=gnu", ".", NULL);
@@ -483,7 +484,8 @@ void do_build(const char *const *argv) {
   if (!c1) {
     m_dup2(p1[0],0); close(p1[0]); close(p1[1]);
     m_dup2(p2[1],1); close(p2[0]); close(p2[1]);
-    if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory);
+    if (chdir(dir))
+      ohshite(_("failed to chdir to `%.255s'"), dir);
     execlp(TAR, "tar", "-cf", "-", "--format=gnu", "--null", "-T", "-", "--no-recursion", NULL);
     ohshite(_("unable to execute %s (%s)"), "tar -cf", TAR);
   }
@@ -505,7 +507,8 @@ void do_build(const char *const *argv) {
   c3 = subproc_fork();
   if (!c3) {
     m_dup2(p3[1],1); close(p3[0]); close(p3[1]);
-    if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory);
+    if (chdir(dir))
+      ohshite(_("failed to chdir to `%.255s'"), dir);
     execlp(FIND, "find", ".", "-path", "./" BUILDCONTROLDIR, "-prune", "-o",
            "-print0", NULL);
     ohshite(_("unable to execute %s (%s)"), "find", FIND);
@@ -513,7 +516,7 @@ void do_build(const char *const *argv) {
   close(p3[1]);
   /* We need to reorder the files so we can make sure that symlinks
    * will not appear before their target. */
-  while ((fi=getfi(directory, p3[0]))!=NULL)
+  while ((fi = getfi(dir, p3[0])) != NULL)
     if (S_ISLNK(fi->st.st_mode))
       add_to_filist(&symlist, &symlist_end, fi);
     else {

+ 1 - 1
dpkg-deb/dpkg-deb.h

@@ -28,7 +28,7 @@ dofunction do_info, do_field, do_extract, do_vextract, do_fsystarfile;
 
 extern int debugflag, nocheckflag, oldformatflag;
 
-void extracthalf(const char *debar, const char *directory,
+void extracthalf(const char *debar, const char *dir,
                  const char *taroption, int admininfo);
 
 extern const char* showformat;

+ 16 - 10
dpkg-deb/extract.c

@@ -121,8 +121,10 @@ parseheaderlength(const char *inh, size_t len,
   return (size_t)r;
 }
 
-void extracthalf(const char *debar, const char *directory,
-                 const char *taroption, int admininfo) {
+void
+extracthalf(const char *debar, const char *dir, const char *taroption,
+            int admininfo)
+{
   char versionbuf[40];
   float versionnum;
   size_t ctrllennum, memberlen= 0;
@@ -300,11 +302,13 @@ void extracthalf(const char *debar, const char *directory,
   close(arfd);
   if (taroption) close(p2[1]);
 
-  if (taroption && directory) {
-    if (chdir(directory)) {
+  if (taroption && dir) {
+    if (chdir(dir)) {
       if (errno == ENOENT) {
-        if (mkdir(directory,0777)) ohshite(_("failed to create directory"));
-        if (chdir(directory)) ohshite(_("failed to chdir to directory after creating it"));
+        if (mkdir(dir, 0777))
+          ohshite(_("failed to create directory"));
+        if (chdir(dir))
+          ohshite(_("failed to chdir to directory after creating it"));
       } else {
         ohshite(_("failed to chdir to directory"));
       }
@@ -346,18 +350,20 @@ void extracthalf(const char *debar, const char *directory,
 static void controlextractvextract(int admin,
                                    const char *taroptions,
                                    const char *const *argv) {
-  const char *debar, *directory;
+  const char *debar, *dir;
 
   if (!(debar= *argv++))
     badusage(_("--%s needs a .deb filename argument"),cipaction->olong);
-  if (!(directory= *argv++)) {
-    if (admin) directory= EXTRACTCONTROLDIR;
+  dir = *argv++;
+  if (!dir) {
+    if (admin)
+      dir = EXTRACTCONTROLDIR;
     else ohshit(_("--%s needs a target directory.\n"
                 "Perhaps you should be using dpkg --install ?"),cipaction->olong);
   } else if (*argv) {
     badusage(_("--%s takes at most two arguments (.deb and directory)"),cipaction->olong);
   }
-  extracthalf(debar, directory, taroptions, admin);
+  extracthalf(debar, dir, taroptions, admin);
 }
 
 void do_fsystarfile(const char *const *argv) {

+ 36 - 30
dpkg-deb/info.c

@@ -49,17 +49,18 @@
 
 static void cu_info_prepare(int argc, void **argv) {
   pid_t c1;
-  char *directory;
+  char *dir;
   struct stat stab;
 
-  directory= (char*)(argv[0]);
+  dir = argv[0];
   if (chdir("/"))
     ohshite(_("failed to chdir to `/' for cleanup"));
-  if (lstat(directory,&stab) && errno==ENOENT) return;
+  if (lstat(dir, &stab) && errno == ENOENT)
+    return;
 
   c1 = subproc_fork();
   if (!c1) {
-    execlp(RM, "rm", "-rf", directory, NULL);
+    execlp(RM, "rm", "-rf", dir, NULL);
     ohshite(_("unable to execute %s (%s)"), _("rm command for cleanup"), RM);
   }
   subproc_wait_check(c1, _("rm command for cleanup"), 0);
@@ -67,7 +68,7 @@ static void cu_info_prepare(int argc, void **argv) {
 
 static void info_prepare(const char *const **argvp,
                          const char **debarp,
-                         const char **directoryp,
+                         const char **dirp,
                          int admininfo) {
   char *dbuf;
 
@@ -77,7 +78,7 @@ static void info_prepare(const char *const **argvp,
   dbuf = mkdtemp(path_make_temp_template("dpkg-deb"));
   if (!dbuf)
     ohshite(_("unable to create temporary directory"));
-  *directoryp= dbuf;
+  *dirp = dbuf;
 
   push_cleanup(cu_info_prepare, -1, NULL, 0, 1, (void *)dbuf);
   extracthalf(*debarp, dbuf, "mx", admininfo);
@@ -87,8 +88,9 @@ static int ilist_select(const struct dirent *de) {
   return strcmp(de->d_name,".") && strcmp(de->d_name,"..");
 }
 
-static void info_spew(const char *debar, const char *directory,
-                      const char *const *argv) {
+static void
+info_spew(const char *debar, const char *dir, const char *const *argv)
+{
   const char *component;
   struct varbuf controlfile = VARBUF_INIT;
   int fd;
@@ -96,7 +98,7 @@ static void info_spew(const char *debar, const char *directory,
 
   while ((component = *argv++) != NULL) {
     varbufreset(&controlfile);
-    varbufaddstr(&controlfile, directory);
+    varbufaddstr(&controlfile, dir);
     varbufaddc(&controlfile, '/');
     varbufaddstr(&controlfile, component);
     varbufaddc(&controlfile, '\0');
@@ -112,7 +114,7 @@ static void info_spew(const char *debar, const char *directory,
       re++;
     } else {
       ohshite(_("open component `%.255s' (in %.255s) failed in an unexpected way"),
-	      component, directory);
+              component, dir);
     }
   }
   varbuf_destroy(&controlfile);
@@ -122,7 +124,9 @@ static void info_spew(const char *debar, const char *directory,
               "%d requested control components are missing", re), re);
 }
 
-static void info_list(const char *debar, const char *directory) {
+static void
+info_list(const char *debar, const char *dir)
+{
   char interpreter[INTERPRETER_MAX+1], *p;
   int il, lines;
   struct dirent **cdlist, *cdep;
@@ -132,15 +136,16 @@ static void info_list(const char *debar, const char *directory) {
   int c;
 
   cdn= scandir(".", &cdlist, &ilist_select, alphasort);
-  if (cdn == -1) ohshite(_("cannot scan directory `%.255s'"),directory);
+  if (cdn == -1)
+    ohshite(_("cannot scan directory `%.255s'"), dir);
 
   for (n = 0; n < cdn; n++) {
     cdep = cdlist[n];
     if (stat(cdep->d_name,&stab))
-      ohshite(_("cannot stat `%.255s' (in `%.255s')"),cdep->d_name,directory);
+      ohshite(_("cannot stat `%.255s' (in `%.255s')"), cdep->d_name, dir);
     if (S_ISREG(stab.st_mode)) {
       if (!(cc= fopen(cdep->d_name,"r")))
-        ohshite(_("cannot open `%.255s' (in `%.255s')"),cdep->d_name,directory);
+        ohshite(_("cannot open `%.255s' (in `%.255s')"), cdep->d_name, dir);
       lines = 0;
       interpreter[0] = '\0';
       if (getc(cc) == '#') {
@@ -156,7 +161,7 @@ static void info_list(const char *debar, const char *directory) {
       }
       while ((c= getc(cc))!= EOF) { if (c == '\n') lines++; }
       if (ferror(cc)) ohshite(_("failed to read `%.255s' (in `%.255s')"),
-                              cdep->d_name,directory);
+                              cdep->d_name, dir);
       fclose(cc);
       printf(_(" %7ld bytes, %5d lines   %c  %-20.127s %.127s\n"),
              (long)stab.st_size, lines, S_IXUSR & stab.st_mode ? '*' : ' ',
@@ -170,7 +175,7 @@ static void info_list(const char *debar, const char *directory) {
 
   if (!(cc= fopen("control","r"))) {
     if (errno != ENOENT)
-      ohshite(_("failed to read `%.255s' (in `%.255s')"), "control", directory);
+      ohshite(_("failed to read `%.255s' (in `%.255s')"), "control", dir);
     fputs(_("(no `control' file in control archive!)\n"), stdout);
   } else {
     lines= 1;
@@ -184,15 +189,16 @@ static void info_list(const char *debar, const char *directory) {
       putc('\n', stdout);
 
     if (ferror(cc))
-      ohshite(_("failed to read `%.255s' (in `%.255s')"), "control", directory);
+      ohshite(_("failed to read `%.255s' (in `%.255s')"), "control", dir);
     fclose(cc);
   }
 
   m_output(stdout, _("<standard output>"));
 }
 
-static void info_field(const char *debar, const char *directory,
-                       const char *const *fields, bool showfieldname)
+static void
+info_field(const char *debar, const char *dir, const char *const *fields,
+           bool showfieldname)
 {
   FILE *cc;
   char fieldname[MAXFIELDNAME+1];
@@ -248,14 +254,14 @@ static void info_field(const char *debar, const char *directory,
 }
 
 void do_showinfo(const char* const* argv) {
-  const char *debar, *directory;
+  const char *debar, *dir;
   struct pkginfo *pkg;
   struct pkg_format_node *fmt = pkg_format_parse(showformat);
 
   if (!fmt)
     ohshit(_("Error in format"));
 
-  info_prepare(&argv,&debar,&directory,1);
+  info_prepare(&argv, &debar, &dir, 1);
 
   parsedb(CONTROLFILE, pdb_recordavailable | pdb_rejectstatus | pdb_ignorefiles,
           &pkg, NULL);
@@ -264,26 +270,26 @@ void do_showinfo(const char* const* argv) {
 
 
 void do_info(const char *const *argv) {
-  const char *debar, *directory;
+  const char *debar, *dir;
 
   if (*argv && argv[1]) {
-    info_prepare(&argv,&debar,&directory,1);
-    info_spew(debar,directory, argv);
+    info_prepare(&argv, &debar, &dir, 1);
+    info_spew(debar, dir, argv);
   } else {
-    info_prepare(&argv,&debar,&directory,2);
-    info_list(debar,directory);
+    info_prepare(&argv, &debar, &dir, 2);
+    info_list(debar, dir);
   }
 }
 
 void do_field(const char *const *argv) {
-  const char *debar, *directory;
+  const char *debar, *dir;
 
-  info_prepare(&argv,&debar,&directory,1);
+  info_prepare(&argv, &debar, &dir, 1);
   if (*argv) {
-    info_field(debar, directory, argv, argv[1] != NULL);
+    info_field(debar, dir, argv, argv[1] != NULL);
   } else {
     static const char *const controlonly[] = { "control", NULL };
-    info_spew(debar,directory, controlonly);
+    info_spew(debar, dir, controlonly);
   }
 }
 

+ 7 - 7
src/archives.c

@@ -437,7 +437,7 @@ tarobject(void *ctx, struct tar_entry *ti)
 
   struct conffile *conff;
   struct tarcontext *tc = ctx;
-  bool existingdirectory, keepexisting;
+  bool existingdir, keepexisting;
   int statr;
   ssize_t r;
   struct stat stab, stabtmp;
@@ -532,23 +532,23 @@ tarobject(void *ctx, struct tar_entry *ti)
   /* Check to see if it's a directory or link to one and we don't need to
    * do anything. This has to be done now so that we don't die due to
    * a file overwriting conflict. */
-  existingdirectory = false;
+  existingdir = false;
   switch (ti->type) {
   case tar_filetype_symlink:
     /* If it's already an existing directory, do nothing. */
     if (!statr && S_ISDIR(stab.st_mode)) {
       debug(dbg_eachfiledetail, "tarobject symlink exists as directory");
-      existingdirectory = true;
+      existingdir = true;
     } else if (!statr && S_ISLNK(stab.st_mode)) {
       if (linktosameexistingdir(ti, fnamevb.buf, &symlinkfn))
-        existingdirectory = true;
+        existingdir = true;
     }
     break;
   case tar_filetype_dir:
     /* If it's already an existing directory, do nothing. */
     if (!stat(fnamevb.buf,&stabtmp) && S_ISDIR(stabtmp.st_mode)) {
       debug(dbg_eachfiledetail, "tarobject directory exists");
-      existingdirectory = true;
+      existingdir = true;
     }
     break;
   case tar_filetype_file:
@@ -563,7 +563,7 @@ tarobject(void *ctx, struct tar_entry *ti)
   }
 
   keepexisting = false;
-  if (!existingdirectory) {
+  if (!existingdir) {
     struct filepackages_iterator *iter;
 
     iter = filepackages_iter_new(nifd->namenode);
@@ -674,7 +674,7 @@ tarobject(void *ctx, struct tar_entry *ti)
     return 0;
   }
 
-  if (existingdirectory)
+  if (existingdir)
     return 0;
 
   /* Now, at this stage we want to make sure neither of .dpkg-new and