1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-01-03 05:35:58 +00:00

Displaying the files in order

Used an in-line filter to make sure the items are displayed in the order they appear in the archive.

Thank you so much for bearing with me as I learn to navigate the codebase!
This commit is contained in:
alighazi288 2024-12-19 13:50:15 -05:00
parent aaf2ffaa4b
commit c9527a4488

View file

@ -56,53 +56,55 @@ def do_extract(self, args, repository, manifest, archive):
else: else:
pi = None pi = None
excluded_items = []
# First pass to identify excluded items
for item in archive.iter_items(preload=True): for item in archive.iter_items(preload=True):
if not matcher.match(item.path):
excluded_items.append(item.path)
for item in archive.iter_items(filter, preload=True):
orig_path = item.path orig_path = item.path
if strip_components: components = orig_path.split(os.sep)
item.path = os.sep.join(orig_path.split(os.sep)[strip_components:]) if strip_components >= len(components):
sanitized_path = ""
else:
sanitized_path = os.sep.join(components[strip_components:])
if not args.dry_run: if not sanitized_path:
while dirs and not item.path.startswith(dirs[-1].path): continue
dir_item = dirs.pop(-1)
try: item.path = sanitized_path
archive.extract_item(dir_item, stdout=stdout)
except BackupError as e:
self.print_warning_instance(BackupWarning(remove_surrogates(dir_item.path), e))
is_matched = matcher.match(item.path) is_matched = matcher.match(item.path)
try: log_prefix = "+" if is_matched else "-"
log_prefix = "+" if is_matched else "-" logging.getLogger("borg.output.list").info(f"{log_prefix} {remove_surrogates(item.path)}")
logging.getLogger("borg.output.list").info(f"{log_prefix} {remove_surrogates(item.path)}")
if dry_run: if is_matched:
archive.extract_item(item, dry_run=True, hlm=hlm, pi=pi)
else: if not args.dry_run:
if is_matched: while dirs and not item.path.startswith(dirs[-1].path):
if stat.S_ISDIR(item.mode): dir_item = dirs.pop(-1)
dirs.append(item) try:
archive.extract_item(item, stdout=stdout, restore_attrs=False) archive.extract_item(dir_item, stdout=stdout)
else: except BackupError as e:
archive.extract_item( self.print_warning_instance(BackupWarning(remove_surrogates(dir_item.path), e))
item,
stdout=stdout, try:
sparse=sparse, if dry_run:
hlm=hlm, archive.extract_item(item, dry_run=True, hlm=hlm, pi=pi)
pi=pi, else:
continue_extraction=continue_extraction, if is_matched:
) if stat.S_ISDIR(item.mode):
except BackupError as e: dirs.append(item)
self.print_warning_instance(BackupWarning(remove_surrogates(orig_path), e)) archive.extract_item(item, stdout=stdout, restore_attrs=False)
else:
archive.extract_item(
item,
stdout=stdout,
sparse=sparse,
hlm=hlm,
pi=pi,
continue_extraction=continue_extraction,
)
except BackupError as e:
self.print_warning_instance(BackupWarning(remove_surrogates(orig_path), e))
if pi: if pi:
pi.finish() pi.finish()
# Display excluded items
if excluded_items:
for excluded_item in excluded_items:
logging.getLogger("borg.output.list").info(f"- {remove_surrogates(excluded_item)}")
if not args.dry_run: if not args.dry_run:
pi = ProgressIndicatorPercent( pi = ProgressIndicatorPercent(