lib/canonicalize: always remove tailing slash

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2012-02-24 21:26:11 +01:00
parent 8a0f727bf2
commit 28074a0952
1 changed files with 10 additions and 3 deletions

View 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))) {