diff mbox

btrfs-progs: Do not add extra slash if given path end with it

Message ID 1522314679-762-1-git-send-email-gujx@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gu Jinxiang March 29, 2018, 9:11 a.m. UTC
When use a given path end with a slash like below,
the output of path will have double slash.

Do not add extra slash if there is already one in the given
path.

$ btrfs filesystem du ./test/
output:
Total   Exclusive  Set shared  Filename
0.00B       0.00B           -  /home/gujx/device/tmp/test//foo

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
---
 cmds-fi-du.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Sterba April 9, 2018, 2:39 p.m. UTC | #1
On Thu, Mar 29, 2018 at 05:11:19PM +0800, Gu Jinxiang wrote:
> When use a given path end with a slash like below,
> the output of path will have double slash.
> 
> Do not add extra slash if there is already one in the given
> path.
> 
> $ btrfs filesystem du ./test/
> output:
> Total   Exclusive  Set shared  Filename
> 0.00B       0.00B           -  /home/gujx/device/tmp/test//foo
> 
> Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>

Applied, thanks.

I was wondering if we should remove all trailing slashes, but I think
that the chance of that happening often is too low. The tab completion
will append only a single tab and that's about the case I'd care.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-fi-du.c b/cmds-fi-du.c
index 8a44665c..74f57320 100644
--- a/cmds-fi-du.c
+++ b/cmds-fi-du.c
@@ -449,7 +449,7 @@  static int du_add_file(const char *filename, int dirfd,
 	}
 
 	pathtmp = pathp;
-	if (pathp == path)
+	if (pathp == path || *(pathp-1) == '/')
 		ret = sprintf(pathp, "%s", filename);
 	else
 		ret = sprintf(pathp, "/%s", filename);