]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
new option "--exclude-caches" for bup-index
authorTim Riemenschneider <git@tim-riemenschneider.de>
Thu, 21 Mar 2013 00:29:23 +0000 (01:29 +0100)
committerTim Riemenschneider <git@tim-riemenschneider.de>
Thu, 2 Jul 2015 20:45:59 +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>
Documentation/bup-index.md
cmd/index-cmd.py
lib/bup/drecurse.py
t/test-index-excludes.sh

index 75506a2424dc89cc0fe16acdd6748cb5fa610176..7b5a6babd6f187ab0b72b999958bc18e04e010a0 100644 (file)
@@ -12,7 +12,7 @@ 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*] [\--exclude-if-present *filename*]
-[-v] \<filenames...\>
+[\--exclude-caches] [-v] \<filenames...\>
 
 # DESCRIPTION
 
@@ -188,6 +188,12 @@ does, due to the accommodations described above.
     So you can "touch .do-not-backup-me" to exclude a directory
     from backup.
 
+\--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 4354eeccc473e97edef1b7a57c5ae6b6573e31cc..c07252b072b70c9cd4c503758559653a088e7d0c 100755 (executable)
@@ -85,7 +85,8 @@ def update_index(top, excluded_paths, exclude_rxs):
                                                  bup_dir=bup_dir,
                                                  excluded_paths=excluded_paths,
                                                  exclude_rxs=exclude_rxs,
-                                                 exclude_if_present=opt['exclude-if-present']):
+                                                 exclude_if_present=opt['exclude-if-present'],
+                                                 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()
@@ -207,6 +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 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 61da2c582a0256ed8902718df361044efff06c86..8404f8b1e6831594d043bf85e3c93d12f53f2c15 100644 (file)
@@ -52,7 +52,8 @@ def _dirlist():
 def _recursive_dirlist(prepend, xdev, bup_dir=None,
                        excluded_paths=None,
                        exclude_rxs=None,
-                       exclude_if_present=None):
+                       exclude_if_present=None,
+                       exclude_caches=None):
     for (name,pst) in _dirlist():
         path = prepend + name
         if excluded_paths:
@@ -65,6 +66,16 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None,
             if exclude_if_present != None and os.path.exists(prepend+name+exclude_if_present):
                 debug1('Skipping %r: exclude-file present.\n' % (prepend+name))
                 continue
+            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')
@@ -81,7 +92,8 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None,
                                                 bup_dir=bup_dir,
                                                 excluded_paths=excluded_paths,
                                                 exclude_rxs=exclude_rxs,
-                                                exclude_if_present=exclude_if_present):
+                                                exclude_if_present=exclude_if_present,
+                                                exclude_caches=exclude_caches):
                         yield i
                     os.chdir('..')
         yield (path, pst)
@@ -89,7 +101,8 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None,
 
 def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None,
                       exclude_rxs=None,
-                      exclude_if_present=None):
+                      exclude_if_present=None,
+                      exclude_caches=None):
     startdir = OsFile('.')
     try:
         assert(type(paths) != type(''))
@@ -119,7 +132,8 @@ def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None,
                                             bup_dir=bup_dir,
                                             excluded_paths=excluded_paths,
                                             exclude_rxs=exclude_rxs,
-                                            exclude_if_present=exclude_if_present):
+                                            exclude_if_present=exclude_if_present,
+                                            exclude_caches=exclude_caches):
                     yield i
                 startdir.fchdir()
             else:
index 5b89d2ec92f042e00ef06bbaa30efcf92334c706..d667a3f4e05cfc5dff5a45008689778fe79072eb 100755 (executable)
@@ -25,3 +25,23 @@ b
 f"
     rm -rf "$D"
 ) || WVFAIL
+
+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