2
0
Эх сурвалжийг харах

--keep-tag-files: fix file status, fix multiple tag files in one directory, fixes #432

Thomas Waldmann 9 жил өмнө
parent
commit
b1ba7a84f0

+ 6 - 3
borg/archiver.py

@@ -210,11 +210,14 @@ class Archiver:
                     status = 'E'
                     self.print_warning('%s: %s', path, e)
         elif stat.S_ISDIR(st.st_mode):
-            tag_path = dir_is_tagged(path, exclude_caches, exclude_if_present)
-            if tag_path:
+            tag_paths = dir_is_tagged(path, exclude_caches, exclude_if_present)
+            if tag_paths:
                 if keep_tag_files:
                     archive.process_dir(path, st)
-                    archive.process_file(tag_path, st, cache)
+                    for tag_path in tag_paths:
+                        self._process(archive, cache, excludes, exclude_caches, exclude_if_present,
+                                      keep_tag_files, skip_inodes, tag_path, restrict_dev,
+                                      read_special=read_special, dry_run=dry_run)
                 return
             if not dry_run:
                 status = archive.process_dir(path, st)

+ 7 - 6
borg/helpers.py

@@ -434,18 +434,19 @@ def dir_is_cachedir(path):
 
 def dir_is_tagged(path, exclude_caches, exclude_if_present):
     """Determines whether the specified path is excluded by being a cache
-    directory or containing the user-specified tag file. Returns the
-    path of the tag file (either CACHEDIR.TAG or the matching
-    user-specified file)
+    directory or containing user-specified tag files. Returns a list of the
+    paths of the tag files (either CACHEDIR.TAG or the matching
+    user-specified files).
     """
+    tag_paths = []
     if exclude_caches and dir_is_cachedir(path):
-        return os.path.join(path, 'CACHEDIR.TAG')
+        tag_paths.append(os.path.join(path, 'CACHEDIR.TAG'))
     if exclude_if_present is not None:
         for tag in exclude_if_present:
             tag_path = os.path.join(path, tag)
             if os.path.isfile(tag_path):
-                return tag_path
-    return None
+                tag_paths.append(tag_path)
+    return tag_paths
 
 
 def format_time(t):

+ 19 - 9
borg/testsuite/archiver.py

@@ -512,17 +512,27 @@ class ArchiverTestCase(ArchiverTestCaseBase):
 
     def test_exclude_keep_tagged(self):
         self.cmd('init', self.repository_location)
-        self.create_regular_file('file1', size=1024 * 80)
-        self.create_regular_file('tagged1/.NOBACKUP')
-        self.create_regular_file('tagged1/file2', size=1024 * 80)
-        self.create_regular_file('tagged2/CACHEDIR.TAG', contents = b'Signature: 8a477f597d28d172789f06886806bc55 extra stuff')
-        self.create_regular_file('tagged2/file3', size=1024 * 80)
-        self.cmd('create', '--exclude-if-present', '.NOBACKUP', '--exclude-caches', '--keep-tag-files', self.repository_location + '::test', 'input')
+        self.create_regular_file('file0', size=1024)
+        self.create_regular_file('tagged1/.NOBACKUP1')
+        self.create_regular_file('tagged1/file1', size=1024)
+        self.create_regular_file('tagged2/.NOBACKUP2')
+        self.create_regular_file('tagged2/file2', size=1024)
+        self.create_regular_file('tagged3/CACHEDIR.TAG', contents = b'Signature: 8a477f597d28d172789f06886806bc55 extra stuff')
+        self.create_regular_file('tagged3/file3', size=1024)
+        self.create_regular_file('taggedall/.NOBACKUP1')
+        self.create_regular_file('taggedall/.NOBACKUP2')
+        self.create_regular_file('taggedall/CACHEDIR.TAG', contents = b'Signature: 8a477f597d28d172789f06886806bc55 extra stuff')
+        self.create_regular_file('taggedall/file4', size=1024)
+        self.cmd('create', '--exclude-if-present', '.NOBACKUP1', '--exclude-if-present', '.NOBACKUP2',
+                 '--exclude-caches', '--keep-tag-files', self.repository_location + '::test', 'input')
         with changedir('output'):
             self.cmd('extract', self.repository_location + '::test')
-        self.assert_equal(sorted(os.listdir('output/input')), ['file1', 'tagged1', 'tagged2'])
-        self.assert_equal(sorted(os.listdir('output/input/tagged1')), ['.NOBACKUP'])
-        self.assert_equal(sorted(os.listdir('output/input/tagged2')), ['CACHEDIR.TAG'])
+        self.assert_equal(sorted(os.listdir('output/input')), ['file0', 'tagged1', 'tagged2', 'tagged3', 'taggedall'])
+        self.assert_equal(os.listdir('output/input/tagged1'), ['.NOBACKUP1'])
+        self.assert_equal(os.listdir('output/input/tagged2'), ['.NOBACKUP2'])
+        self.assert_equal(os.listdir('output/input/tagged3'), ['CACHEDIR.TAG'])
+        self.assert_equal(sorted(os.listdir('output/input/taggedall')),
+                          ['.NOBACKUP1', '.NOBACKUP2', 'CACHEDIR.TAG', ])
 
     def test_path_normalization(self):
         self.cmd('init', self.repository_location)