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

PR #284 updated - Merge branch 'sparse_files' into merge

Thomas Waldmann 10 жил өмнө
parent
commit
99d15157d2

+ 2 - 2
attic/archive.py

@@ -246,7 +246,7 @@ class Archive:
         cache.rollback()
         return stats
 
-    def extract_item(self, item, restore_attrs=True, dry_run=False, stdout=False):
+    def extract_item(self, item, restore_attrs=True, dry_run=False, stdout=False, sparse=False):
         if dry_run or stdout:
             if b'chunks' in item:
                 for data in self.pipeline.fetch_many([c[0] for c in item[b'chunks']], is_preloaded=True):
@@ -288,7 +288,7 @@ class Archive:
                 with open(path, 'wb') as fd:
                     ids = [c[0] for c in item[b'chunks']]
                     for data in self.pipeline.fetch_many(ids, is_preloaded=True):
-                        if ZEROS.startswith(data):
+                        if sparse and ZEROS.startswith(data):
                             # all-zero chunk: create a hole in a sparse file
                             fd.seek(len(data), 1)
                         else:

+ 5 - 1
attic/archiver.py

@@ -221,6 +221,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
         patterns = adjust_patterns(args.paths, args.excludes)
         dry_run = args.dry_run
         stdout = args.stdout
+        sparse = args.sparse
         strip_components = args.strip_components
         dirs = []
         for item in archive.iter_items(lambda item: not exclude_path(item[b'path'], patterns), preload=True):
@@ -241,7 +242,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
                         dirs.append(item)
                         archive.extract_item(item, restore_attrs=False)
                     else:
-                        archive.extract_item(item, stdout=stdout)
+                        archive.extract_item(item, stdout=stdout, sparse=sparse)
             except IOError as e:
                 self.print_error('%s: %s', remove_surrogates(orig_path), e)
 
@@ -648,6 +649,9 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
         subparser.add_argument('--stdout', dest='stdout',
                                action='store_true', default=False,
                                help='write all extracted data to stdout')
+        subparser.add_argument('--sparse', dest='sparse',
+                               action='store_true', default=False,
+                               help='create holes in output sparse file from all-zero chunks')
         subparser.add_argument('archive', metavar='ARCHIVE',
                                type=location_validator(archive=True),
                                help='archive to extract')

+ 1 - 1
attic/testsuite/archiver.py

@@ -225,7 +225,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.attic('init', self.repository_location)
         self.attic('create', self.repository_location + '::test', 'input')
         with changedir('output'):
-            self.attic('extract', self.repository_location + '::test')
+            self.attic('extract', '--sparse', self.repository_location + '::test')
         self.assert_dirs_equal('input', 'output/input')
         filename = os.path.join(self.output_path, 'input', 'sparse')
         with open(filename, 'rb') as fd: