From a7a672cae871aa9cf9cc003a37579cb4df51b3fe Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Wed, 1 Sep 2021 12:38:14 -0400 Subject: [PATCH] fs: Trim trailing lsmount and flushmount path slashes Remove trailing slashes from paths given to `fs lsmount` and `fs flushmount`. This makes for a more pleasant user experience when shell tab completion is used to specify the paths. Thanks to Stephan Wiesand for pointing out this issue. Change-Id: I756c4d7d9b3fe5cd41e02165caf1d6866a0210e6 Reviewed-on: https://gerrit.openafs.org/14779 Tested-by: BuildBot Reviewed-by: Stephan Wiesand Reviewed-by: Benjamin Kaduk --- src/venus/fs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/venus/fs.c b/src/venus/fs.c index 103f309..dea459b 100644 --- a/src/venus/fs.c +++ b/src/venus/fs.c @@ -1733,6 +1733,7 @@ GetLastComponent(const char *data, char **outdir, char **outbase, int link_chars_read; /*Num chars read in readlink() */ char *dirname = NULL; char *basename = NULL; + size_t len; *outbase = NULL; *outdir = NULL; @@ -1785,6 +1786,13 @@ GetLastComponent(const char *data, char **outdir, char **outbase, strcpy(true_name, orig_name); } + /* Trim trailing slashes, if any. */ + len = strlen(true_name); + while (len > 1 && true_name[len - 1] == '/') { + true_name[len - 1 ] = '\0'; + len--; + } + /* Find rightmost slash, if any. */ lastSlash = strrchr(true_name, '/'); if (lastSlash == true_name) { -- 1.9.4