]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
new option "--exclude-caches" for bup-index
authorTim Riemenschneider <git@tim-riemenschneider.de>
Thu, 5 Jun 2014 21:36:45 +0000 (23:36 +0200)
committerTim Riemenschneider <git@tim-riemenschneider.de>
Thu, 2 Jul 2015 20:45:07 +0000 (22:45 +0200)
Excludes all directories that contain a file CACHEDIR.TAG that begins with
"Signature: 8a477f597d28d172789f06886806bc55".

See http://www.brynosaurus.com/cachedir/ for more information about
cache-directory tagging.

Signed-off-by: Tim Riemenschneider <git@tim-riemenschneider.de>
Conflicts:
Documentation/bup-index.md
cmd/index-cmd.py
lib/bup/drecurse.py
t/test-index-excludes.sh

Documentation/bup-index.md
Makefile
cmd/index-cmd.py
lib/bup/drecurse.py
t/test-index-excludes.sh [new file with mode: 0755]

index d85d17969b2d82bef736199aeac9fd60e33ffe64..a2c198d71e3d756bce39ec7da4af878673c2cb18 100644 (file)
@@ -11,7 +11,7 @@ bup-index - print and/or update the bup filesystem index
 bup index \<-p|-m|-s|-u|\--clear|\--check\> [-H] [-l] [-x] [\--fake-valid]
 [\--no-check-device] [\--fake-invalid] [-f *indexfile*] [\--exclude *path*]
 [\--exclude-from *filename*] [\--exclude-rx *pattern*]
-[\--exclude-rx-from *filename*] [-v] \<filenames...\>
+[\--exclude-rx-from *filename*] [\--exclude-caches] [-v] \<filenames...\>
 
 # DESCRIPTION
 
@@ -182,6 +182,13 @@ does, due to the accommodations described above.
 :   read --exclude-rx patterns from *filename*, one pattern per-line
     (may be repeated).  Ignore completely empty lines.
 
+
+\--exclude-caches
+:   exclude all directories that contain a file CACHEDIR.TAG, whose
+    content begins with "Signature: 8a477f597d28d172789f06886806bc55".
+    For more information on cachedir-tagging, see
+    http://www.brynosaurus.com/cachedir/
+
 \--no-check-device
 :   don't mark a an entry invalid if the device number (stat(2)
     st_dev) changes.  This can be useful when indexing remote,
index 988a9cc91ab8856755476f56278edf0d4f010dd8..521fed01f54ee8de2044f007615badf1242835d2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -110,6 +110,7 @@ cmdline_tests := \
   t/test-ls.sh \
   t/test-meta.sh \
   t/test-on.sh \
+  t/test-index-excludes.sh \
   t/test-restore-map-owner.sh \
   t/test-restore-single-file.sh \
   t/test-rm-between-index-and-save.sh \
index 6f2adf4e581c1dc288babe4bee3525c2f61ea004..3309398ed19ed7908eb91ce4c5eae4660e4caf66 100755 (executable)
@@ -84,7 +84,8 @@ def update_index(top, excluded_paths, exclude_rxs):
     for (path,pst) in drecurse.recursive_dirlist([top], xdev=opt.xdev,
                                                  bup_dir=bup_dir,
                                                  excluded_paths=excluded_paths,
-                                                 exclude_rxs=exclude_rxs):
+                                                 exclude_rxs=exclude_rxs,
+                                                 exclude_caches=opt.exclude_caches):
         if opt.verbose>=2 or (opt.verbose==1 and stat.S_ISDIR(pst.st_mode)):
             sys.stdout.write('%s\n' % path)
             sys.stdout.flush()
@@ -205,6 +206,7 @@ exclude= a path to exclude from the backup (may be repeated)
 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-caches exclude CACHEDIR.TAG-directories
 v,verbose  increase log output (can be used more than once)
 x,xdev,one-file-system  don't cross filesystem boundaries
 """
index 6be7fa2ff38f8ff7bd6de1d87e9536372c9448fe..4f404150f25c74b55858c125a77f7e9baa583568 100644 (file)
@@ -51,7 +51,8 @@ def _dirlist():
 
 def _recursive_dirlist(prepend, xdev, bup_dir=None,
                        excluded_paths=None,
-                       exclude_rxs=None):
+                       exclude_rxs=None,
+                       exclude_caches=None):
     for (name,pst) in _dirlist():
         path = prepend + name
         if excluded_paths:
@@ -61,6 +62,16 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None,
         if exclude_rxs and should_rx_exclude_path(path, exclude_rxs):
             continue
         if name.endswith('/'):
+            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')
+                    data = f.read(len(tag_contents))
+                    f.close()
+                    if data == tag_contents:
+                        debug1('Skipping %r: excluding cache dir' % (prepend+name))
+                        continue
             if bup_dir != None:
                 if os.path.normpath(path) == bup_dir:
                     debug1('Skipping BUP_DIR.\n')
@@ -76,14 +87,16 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None,
                     for i in _recursive_dirlist(prepend=prepend+name, xdev=xdev,
                                                 bup_dir=bup_dir,
                                                 excluded_paths=excluded_paths,
-                                                exclude_rxs=exclude_rxs):
+                                                exclude_rxs=exclude_rxs,
+                                                exclude_caches=exclude_caches):
                         yield i
                     os.chdir('..')
         yield (path, pst)
 
 
 def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None,
-                      exclude_rxs=None):
+                      exclude_rxs=None,
+                      exclude_caches=None):
     startdir = OsFile('.')
     try:
         assert(type(paths) != type(''))
@@ -112,7 +125,8 @@ def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None,
                 for i in _recursive_dirlist(prepend=prepend, xdev=xdev,
                                             bup_dir=bup_dir,
                                             excluded_paths=excluded_paths,
-                                            exclude_rxs=exclude_rxs):
+                                            exclude_rxs=exclude_rxs,
+                                            exclude_caches=exclude_caches):
                     yield i
                 startdir.fchdir()
             else:
diff --git a/t/test-index-excludes.sh b/t/test-index-excludes.sh
new file mode 100755 (executable)
index 0000000..86e5bc8
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+. ./wvtest-bup.sh
+. t/lib.sh
+
+top="$(pwd)"
+bup() { "$top/bup" "$@"; }
+
+WVSTART "exclude-caches"
+(
+    set -e -o pipefail
+    D="$(wvmktempdir)"
+    force-delete $D
+    mkdir $D
+    export BUP_DIR="$D/.bup"
+    WVPASS bup init
+    touch $D/a
+    WVPASS bup random 128k >$D/b
+    mkdir $D/d $D/d/e
+    WVPASS bup random 512 >$D/f
+    echo 'Signature: 8a477f597d28d172789f06886806bc55' > $D/d/CACHEDIR.TAG
+    WVPASS bup index -ux --exclude-caches $D
+    bup save -n exclude $D
+    WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
+b
+f"
+) || WVFAIL