From: Avery Pennarun Date: Sat, 8 Jan 2011 09:59:55 +0000 (-0800) Subject: Merge branch 'next' into 'master' X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=72eab171e4c8314d39a43ac59274da2d90dd0d7c;p=packages%2Fb%2Fbup.git Merge branch 'next' into 'master' * 'next': Change server_mode=='dumb' to just a dumb_server_mode bool. Teach bup about URLs and non-ssh remotes Don't generate midx files in dumb server mode Add optional dumb-server mode git.CatPipe: set a buffer size on the subprocess to increase performance. Improve test pass condition Adds examples for strip, strip-prefix and graft to bup save's documentation Adds --graft option to bup save. Conflicts: lib/bup/t/thelpers.py --- 72eab171e4c8314d39a43ac59274da2d90dd0d7c diff --cc lib/bup/helpers.py index 7c11a92,ae3b1cb..a5b12e0 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@@ -438,13 -440,20 +440,21 @@@ 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 + def graft_path(graft_points, path): - normalized_path = realpath(path) ++ normalized_path = os.path.realpath(path) + for graft_point in graft_points: + old_prefix, new_prefix = graft_point + if normalized_path.startswith(old_prefix): + return re.sub(r'^' + old_prefix, new_prefix, normalized_path) + return normalized_path + # hashlib is only available in python 2.5 or higher, but the 'sha' module # produces a DeprecationWarning in python 2.6 or higher. We want to support diff --cc lib/bup/t/thelpers.py index ebb80f8,17f6bcd..89cccda --- a/lib/bup/t/thelpers.py +++ b/lib/bup/t/thelpers.py @@@ -30,24 -29,25 +30,46 @@@ def test_strip_base_path() base_paths = ["/var", "/var/backup", "/var/backup/daily.0/localhost"] WVPASSEQ(strip_base_path(path, base_paths), '/etc') +@wvtest +def test_strip_symlinked_base_path(): + tmpdir = os.path.join(os.getcwd(),"test_strip_symlinked_base_path.tmp") + symlink_src = os.path.join(tmpdir, "private", "var") + symlink_dst = os.path.join(tmpdir, "var") + path = os.path.join(symlink_dst, "a") + + os.mkdir(tmpdir) + os.mkdir(os.path.join(tmpdir, "private")) + os.mkdir(symlink_src) + os.symlink(symlink_src, symlink_dst) + + result = strip_base_path(path, [symlink_dst]) + + os.remove(symlink_dst) + os.rmdir(symlink_src) + os.rmdir(os.path.join(tmpdir, "private")) + os.rmdir(tmpdir) + + WVPASSEQ(result, "/a") + + @wvtest + def test_graft_path(): + middle_matching_old_path = "/user" + non_matching_old_path = "/usr" + matching_old_path = "/home" + matching_full_path = "/home/user" + new_path = "/opt" + + all_graft_points = [(middle_matching_old_path, new_path), + (non_matching_old_path, new_path), + (matching_old_path, new_path)] + + path = "/home/user/" + + WVPASSEQ(graft_path([(middle_matching_old_path, new_path)], path), + "/home/user") + WVPASSEQ(graft_path([(non_matching_old_path, new_path)], path), + "/home/user") + WVPASSEQ(graft_path([(matching_old_path, new_path)], path), "/opt/user") + WVPASSEQ(graft_path(all_graft_points, path), "/opt/user") + WVPASSEQ(graft_path([(matching_full_path, new_path)], path), + "/opt")