]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/canonicalize: always remove tailing slash
authorKarel Zak <kzak@redhat.com>
Fri, 24 Feb 2012 20:26:11 +0000 (21:26 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 24 Feb 2012 20:26:11 +0000 (21:26 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/canonicalize.c

index ab32c10431bd88dde3b9b6fff3c88224c28f4811..fd18af42cee76e58070c8e390300364109510b09 100644 (file)
@@ -174,9 +174,16 @@ canonicalize_path(const char *path)
        if (path == NULL)
                return NULL;
 
-       if (!myrealpath(path, canonical, PATH_MAX+1))
-               return strdup(path);
-
+       if (!myrealpath(path, canonical, PATH_MAX+1)) {
+               char *res = strdup(path);
+               if (res) {
+                       p = strrchr(res, '/');
+                       /* delete trailing slash */
+                       if (p && p > res && *(p + 1) == '\0')
+                               *p = '\0';
+               }
+               return res;
+       }
 
        p = strrchr(canonical, '/');
        if (p && strncmp(p, "/dm-", 4) == 0 && isdigit(*(p + 4))) {