From 4b8fa5d8ad97056eb4e5ec4c60ba223520570e0a Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 24 Nov 2002 16:12:52 +0000 Subject: [PATCH] =?utf8?q?(du=5Ffiles):=20Don't=20strip=20any=20trailing?= =?utf8?q?=20slash.=20Rewrite=20so=20that=20`/'=20is=20no=20longer=20repre?= =?utf8?q?sented=20internally=20as=20the=20empty=20string.=20(count=5Fentr?= =?utf8?q?y):=20When=20appending=20a=20file=20name=20component,=20account?= =?utf8?q?=20for=20the=20fact=20that=20the=20current=20path=20may=20end=20?= =?utf8?q?in=20`/'.=20Fran=E7ois=20Pinard=20reported=20that=20`du=20symlin?= =?utf8?q?k-to-dir/'=20was=20not=20equivalent=20to=20`du=20symlink-to-dir/?= =?utf8?q?.'.=20=20Now=20it=20is.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/du.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/du.c b/src/du.c index 0619507a70..65ed2cff9c 100644 --- 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); -- 2.47.2