]> arthur.barton.de Git - bup.git/commitdiff
Fix a bug in strip_path when prefix is a symlink
authorZoran Zaric <zz@zoranzaric.de>
Fri, 7 Jan 2011 11:16:24 +0000 (12:16 +0100)
committerAvery Pennarun <apenwarr@gmail.com>
Sat, 8 Jan 2011 09:48:57 +0000 (01:48 -0800)
helpers.realpath() wasn't the right choice for path normalization.
The prefix itself can be a symlink, too.  Now we use os.path.realpath(),
which also follows symlinks for the last element.

Signed-off-by: Zoran Zaric <zz@zoranzaric.de>
lib/bup/helpers.py

index cb378a97421cd53363b853e214eca51959b4314d..7c11a927ad2a776298c58abf6c39f2778eff4e2c 100644 (file)
@@ -421,9 +421,9 @@ def strip_path(prefix, path):
     if prefix == None:
         raise Exception('no path given')
 
-    normalized_prefix = realpath(prefix)
+    normalized_prefix = os.path.realpath(prefix)
     debug2("normalized_prefix: %s\n" % normalized_prefix)
-    normalized_path = realpath(path)
+    normalized_path = os.path.realpath(path)
     debug2("normalized_path: %s\n" % normalized_path)
     if normalized_path.startswith(normalized_prefix):
         return normalized_path[len(normalized_prefix):]
@@ -438,10 +438,11 @@ def strip_base_path(path, base_paths):
     Iterates over all base_paths from long to short, to prevent that
     a too short base_path is removed.
     """
+    normalized_path = os.path.realpath(path)
     sorted_base_paths = sorted(base_paths, key=len, reverse=True)
     for bp in sorted_base_paths:
-        if path.startswith(realpath(bp)):
-            return strip_path(bp, path)
+        if normalized_path.startswith(os.path.realpath(bp)):
+            return strip_path(bp, normalized_path)
     return path