Browse Source

cachedir: Add CACHEDIR.TAG file to attic cache dirs

Jonas Borgström 11 years ago
parent
commit
a87a019608
4 changed files with 14 additions and 4 deletions
  1. 1 1
      AUTHORS
  2. 2 0
      CHANGES
  3. 7 0
      attic/archiver.py
  4. 4 3
      attic/helpers.py

+ 1 - 1
AUTHORS

@@ -10,6 +10,6 @@ Patches and Suggestions
 ```````````````````````
 - Brian Johnson
 - Dan Christensen
+- Jeremy Maitin-Shepard
 - Johann Klähn
 - Petros Moisiadis
-

+ 2 - 0
CHANGES

@@ -11,6 +11,8 @@ Version 0.13
 - Experimental Linux and FreeBSD ACL support (#66)
 - Added support for backup and restore of BSDFlags (OSX, FreeBSD) (#56)
 - Fix bug where xattrs on symlinks were not correctly restored
+- Added cachedir support. CACHEDIR.TAG compatible cache directories
+  can now be excluded using ``--exclude-caches`` (#74)
 
 Version 0.12
 ------------

+ 7 - 0
attic/archiver.py

@@ -427,6 +427,13 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
         if not os.path.exists(cache_dir):
             os.makedirs(cache_dir)
             os.chmod(cache_dir, stat.S_IRWXU)
+            with open(os.path.join(cache_dir, 'CACHEDIR.TAG'), 'w') as fd:
+                fd.write(textwrap.dedent("""
+                    Signature: 8a477f597d28d172789f06886806bc55
+                    # This file is a cache directory tag created by Attic.
+                    # For information about cache directory tags, see:
+                    #       http://www.brynosaurus.com/cachedir/
+                    """).lstrip())
         common_parser = argparse.ArgumentParser(add_help=False)
         common_parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
                             default=False,

+ 4 - 3
attic/helpers.py

@@ -245,6 +245,7 @@ class ExcludePattern(IncludePattern):
     def __repr__(self):
         return '%s(%s)' % (type(self), self.pattern)
 
+
 def is_cachedir(path):
     """Determines whether the specified path is a cache directory (and
     therefore should potentially be excluded from the backup) according to
@@ -252,7 +253,6 @@ def is_cachedir(path):
     (http://www.brynosaurus.com/cachedir/spec.html).
     """
 
-    tag_filename = 'CACHEDIR.TAG'
     tag_contents = b'Signature: 8a477f597d28d172789f06886806bc55'
     tag_path = os.path.join(path, 'CACHEDIR.TAG')
     try:
@@ -261,10 +261,11 @@ def is_cachedir(path):
                 tag_data = tag_file.read(len(tag_contents))
                 if tag_data == tag_contents:
                     return True
-    except OSError as e:
-        raise
+    except OSError:
+        pass
     return False
 
+
 def walk_path(path, skip_inodes=None):
     st = os.lstat(path)
     if skip_inodes and (st.st_ino, st.st_dev) in skip_inodes: