]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(du_files): Don't strip any trailing slash.
authorJim Meyering <jim@meyering.net>
Sun, 24 Nov 2002 16:12:52 +0000 (16:12 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 24 Nov 2002 16:12:52 +0000 (16:12 +0000)
Rewrite so that `/' is no longer represented internally as
the empty string.
(count_entry): When appending a file name component,
account for the fact that the current path may end in `/'.
François Pinard reported that `du symlink-to-dir/' was not
equivalent to `du symlink-to-dir/.'.  Now it is.

src/du.c

index 0619507a7030d8564ad2779c50dc8991c2c061cf..65ed2cff9cc21b7a9c29b32bfbbe431712cf930c 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -427,6 +427,7 @@ count_entry (const char *ent, int top, dev_t last_dev, int depth)
   if (S_ISDIR (stat_buf.st_mode))
     {
       unsigned pathlen;
+      unsigned prev_len;
       dev_t dir_dev;
       char *name_space;
       char *namep;
@@ -488,7 +489,9 @@ count_entry (const char *ent, int top, dev_t last_dev, int depth)
 
       /* Remember the current path.  */
 
-      str_concatc (path, "/");
+      prev_len = path->length;
+      if (prev_len && path->text[prev_len - 1] != '/')
+       str_concatc (path, "/");
       pathlen = path->length;
 
       for (namep = name_space; *namep; namep += strlen (namep) + 1)
@@ -504,7 +507,7 @@ count_entry (const char *ent, int top, dev_t last_dev, int depth)
       free (name_space);
       pop_dir (cwd, path->text);
 
-      str_trunc (path, pathlen - 1); /* Remove the "/" we added.  */
+      str_trunc (path, prev_len); /* Remove any "/" we added.  */
       if (depth <= max_depth || top)
        print_size (size, path->length > 0 ? path->text : "/");
       return opt_separate_dirs ? 0 : size;
@@ -530,24 +533,8 @@ du_files (char **files)
 
   for (i = 0; files[i]; i++)
     {
-      char *arg;
-      int s;
-
-      arg = files[i];
-
-      /* Delete final slash in the argument, unless the slash is alone.  */
-      s = strlen (arg) - 1;
-      if (s != 0)
-       {
-         if (arg[s] == '/')
-           arg[s] = 0;
-
-         str_copyc (path, arg);
-       }
-      else if (arg[0] == '/')
-       str_trunc (path, 0);    /* Null path for root directory.  */
-      else
-       str_copyc (path, arg);
+      char const *arg = files[i];
+      str_copyc (path, arg);
 
       if (!print_totals)
        hash_clear (htab);