From 1c5ffa75605ba570b913fb3919c0edda8c7ecfaa Mon Sep 17 00:00:00 2001 From: Tim Riemenschneider Date: Sat, 22 Nov 2014 15:46:55 +0100 Subject: [PATCH] Match tar's "--exclude-caches"-semantic With --exclude-caches, only exclude the directory contents (without the tag-file itself), thus matching tar's semantic (The previous implementation matched tar's "--exclude-caches-all") (cherr-picked from proposed/index-exclude-caches branch: e1f95c0d) Signed-off-by: Tim Riemenschneider --- Documentation/bup-index.md | 5 +++-- cmd/index-cmd.py | 2 +- lib/bup/drecurse.py | 12 ++++++++++-- t/test-index-excludes.sh | 3 +++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Documentation/bup-index.md b/Documentation/bup-index.md index 7b5a6ba..1638d65 100644 --- a/Documentation/bup-index.md +++ b/Documentation/bup-index.md @@ -189,8 +189,9 @@ does, due to the accommodations described above. from backup. \--exclude-caches -: exclude all directories that contain a file CACHEDIR.TAG, whose - content begins with "Signature: 8a477f597d28d172789f06886806bc55". +: exclude the contents of all directories that contain a file CACHEDIR.TAG, + whose content begins with "Signature: 8a477f597d28d172789f06886806bc55", + except for the directory and the tag file itself. For more information on cachedir-tagging, see http://www.brynosaurus.com/cachedir/ diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py index 5bdcc43..833206a 100755 --- a/cmd/index-cmd.py +++ b/cmd/index-cmd.py @@ -208,7 +208,7 @@ exclude-from= skip --exclude paths in file (may be repeated) exclude-rx= skip paths matching the unanchored regex (may be repeated) exclude-rx-from= skip --exclude-rx patterns in file (may be repeated) exclude-if-present= exclude directory if the given file is present -exclude-caches exclude directories containing a CACHEDIR.TAG +exclude-caches exclude directories containing a CACHEDIR.TAG, except for the tag file itself v,verbose increase log output (can be used more than once) x,xdev,one-file-system don't cross filesystem boundaries """ diff --git a/lib/bup/drecurse.py b/lib/bup/drecurse.py index a2d78ae..ec24c8c 100644 --- a/lib/bup/drecurse.py +++ b/lib/bup/drecurse.py @@ -69,14 +69,22 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None, if exclude_caches: tag_filename = 'CACHEDIR.TAG' tag_contents = 'Signature: 8a477f597d28d172789f06886806bc55' - if os.path.exists(prepend+name+tag_filename): - f = open(prepend+name+tag_filename, 'rb') + tag_path = path+tag_filename + if os.path.exists(tag_path): + f = open(tag_path, 'rb') try: data = f.read(len(tag_contents)) finally: f.close() if data == tag_contents: debug1('Skipping %r: excluding cache dir' % (prepend+name)) + try: + st = xstat.lstat(tag_path) + except OSError, e: + add_error(Exception('%s: %s' % (realpath(tag_path), str(e)))) + # CACHEDIR.TAG matched -> only backup the tagfile and the dir-node itself + yield (tag_path, st) + yield (path, pst) continue if bup_dir != None: if os.path.normpath(path) == bup_dir: diff --git a/t/test-index-excludes.sh b/t/test-index-excludes.sh index 6c5e3a8..04a93a0 100755 --- a/t/test-index-excludes.sh +++ b/t/test-index-excludes.sh @@ -36,11 +36,14 @@ WVSTART "exclude-caches" WVPASS touch $D/a WVPASS bup random 128k >$D/b WVPASS mkdir $D/d $D/d/e + WVPASS touch $D/d/file WVPASS bup random 512 >$D/f WVPASS echo 'Signature: 8a477f597d28d172789f06886806bc55' > $D/d/CACHEDIR.TAG WVPASS bup index -ux --exclude-caches $D WVPASS bup save -n exclude $D WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a b +d f" + WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/d/)" "CACHEDIR.TAG" ) || WVFAIL -- 2.39.5