1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-23 14:41:43 +00:00

extract: if --stdout is given, write all extracted binary data to stdout

This commit is contained in:
Thomas Waldmann 2015-03-01 05:07:29 +01:00
parent a3f335e0ff
commit aab900b169
2 changed files with 13 additions and 6 deletions

View file

@ -230,11 +230,14 @@ def add_file_chunks(chunks):
cache.rollback()
return stats
def extract_item(self, item, restore_attrs=True, dry_run=False):
if dry_run:
def extract_item(self, item, restore_attrs=True, dry_run=False, stdout=False):
if dry_run or stdout:
if b'chunks' in item:
for _ in self.pipeline.fetch_many([c[0] for c in item[b'chunks']], is_preloaded=True):
pass
for data in self.pipeline.fetch_many([c[0] for c in item[b'chunks']], is_preloaded=True):
if stdout:
sys.stdout.buffer.write(data)
if stdout:
sys.stdout.buffer.flush()
return
dest = self.cwd

View file

@ -202,6 +202,7 @@ def do_extract(self, args):
numeric_owner=args.numeric_owner)
patterns = adjust_patterns(args.paths, args.excludes)
dry_run = args.dry_run
stdout = args.stdout
strip_components = args.strip_components
dirs = []
for item in archive.iter_items(lambda item: not exclude_path(item[b'path'], patterns), preload=True):
@ -212,7 +213,7 @@ def do_extract(self, args):
continue
if not args.dry_run:
while dirs and not item[b'path'].startswith(dirs[-1][b'path']):
archive.extract_item(dirs.pop(-1))
archive.extract_item(dirs.pop(-1), stdout=stdout)
self.print_verbose(remove_surrogates(orig_path))
try:
if dry_run:
@ -222,7 +223,7 @@ def do_extract(self, args):
dirs.append(item)
archive.extract_item(item, restore_attrs=False)
else:
archive.extract_item(item)
archive.extract_item(item, stdout=stdout)
except IOError as e:
self.print_error('%s: %s', remove_surrogates(orig_path), e)
@ -592,6 +593,9 @@ def run(self, args=None):
subparser.add_argument('--strip-components', dest='strip_components',
type=int, default=0, metavar='NUMBER',
help='Remove the specified number of leading path elements. Pathnames with fewer elements will be silently skipped.')
subparser.add_argument('--stdout', dest='stdout',
action='store_true', default=False,
help='write all extracted data to stdout')
subparser.add_argument('archive', metavar='ARCHIVE',
type=location_validator(archive=True),
help='archive to extract')