Skip to content

Commit

Permalink
Displaying the files in order
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
alighazi288 committed Dec 19, 2024
1 parent aaf2ffa commit c9527a4
Showing 1 changed file with 42 additions and 40 deletions.
82 changes: 42 additions & 40 deletions src/borg/archiver/extract_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,53 +56,55 @@ def do_extract(self, args, repository, manifest, archive):
else:
pi = None

excluded_items = []
# First pass to identify excluded items
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
if strip_components:
item.path = os.sep.join(orig_path.split(os.sep)[strip_components:])
components = orig_path.split(os.sep)
if strip_components >= len(components):
sanitized_path = ""
else:
sanitized_path = os.sep.join(components[strip_components:])

if not sanitized_path:
continue

if not args.dry_run:
while dirs and not item.path.startswith(dirs[-1].path):
dir_item = dirs.pop(-1)
try:
archive.extract_item(dir_item, stdout=stdout)
except BackupError as e:
self.print_warning_instance(BackupWarning(remove_surrogates(dir_item.path), e))
item.path = sanitized_path

is_matched = matcher.match(item.path)
try:
log_prefix = "+" if is_matched else "-"
logging.getLogger("borg.output.list").info(f"{log_prefix} {remove_surrogates(item.path)}")
if dry_run:
archive.extract_item(item, dry_run=True, hlm=hlm, pi=pi)
else:
if is_matched:
if stat.S_ISDIR(item.mode):
dirs.append(item)
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))
log_prefix = "+" if is_matched else "-"
logging.getLogger("borg.output.list").info(f"{log_prefix} {remove_surrogates(item.path)}")

if is_matched:

if not args.dry_run:
while dirs and not item.path.startswith(dirs[-1].path):
dir_item = dirs.pop(-1)
try:
archive.extract_item(dir_item, stdout=stdout)
except BackupError as e:
self.print_warning_instance(BackupWarning(remove_surrogates(dir_item.path), e))

try:
if dry_run:
archive.extract_item(item, dry_run=True, hlm=hlm, pi=pi)
else:
if is_matched:
if stat.S_ISDIR(item.mode):
dirs.append(item)
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:
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:
pi = ProgressIndicatorPercent(
Expand Down

0 comments on commit c9527a4

Please sign in to comment.