summaryrefslogtreecommitdiff
path: root/testing/util-linux/lib-canonicalize-always-remove-tailing-slash.patch
blob: 3b830a2ad10b4019bb3081c87cc7722188c0284d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
From 28074a0952469aebf021821d95238cfb964d13ff Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Fri, 24 Feb 2012 21:26:11 +0100
Subject: [PATCH 09/12] lib/canonicalize: always remove tailing slash

Signed-off-by: Karel Zak <kzak@redhat.com>
---
 lib/canonicalize.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index ab32c10..fd18af4 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -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))) {
-- 
1.7.9.2