Skip to content

Commit aaf2ffa

Browse files
committed
Implemented a dual-pass system to identify and log excluded items separately.
1 parent f8faa5e commit aaf2ffa

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/borg/archiver/extract_cmd.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def do_extract(self, args, repository, manifest, archive):
3838
matcher = build_matcher(args.patterns, args.paths)
3939

4040
progress = args.progress
41-
output_list = args.output_list
4241
dry_run = args.dry_run
4342
stdout = args.stdout
4443
sparse = args.sparse
@@ -48,6 +47,7 @@ def do_extract(self, args, repository, manifest, archive):
4847
hlm = HardLinkManager(id_type=bytes, info_type=str) # hlid -> path
4948

5049
filter = build_filter(matcher, strip_components)
50+
5151
if progress:
5252
pi = ProgressIndicatorPercent(msg="%5.1f%% Extracting: %s", step=0.1, msgid="extract")
5353
pi.output("Calculating total archive size for the progress indicator (might take long for large archives)")
@@ -56,9 +56,13 @@ def do_extract(self, args, repository, manifest, archive):
5656
else:
5757
pi = None
5858

59-
all_items = list(archive.iter_items(preload=True))
59+
excluded_items = []
60+
# First pass to identify excluded items
61+
for item in archive.iter_items(preload=True):
62+
if not matcher.match(item.path):
63+
excluded_items.append(item.path)
6064

61-
for item in all_items:
65+
for item in archive.iter_items(filter, preload=True):
6266
orig_path = item.path
6367
if strip_components:
6468
item.path = os.sep.join(orig_path.split(os.sep)[strip_components:])
@@ -71,29 +75,34 @@ def do_extract(self, args, repository, manifest, archive):
7175
except BackupError as e:
7276
self.print_warning_instance(BackupWarning(remove_surrogates(dir_item.path), e))
7377

74-
if output_list and matcher.match(item.path):
75-
logging.getLogger("borg.output.list").info(remove_surrogates(item.path))
78+
is_matched = matcher.match(item.path)
7679
try:
80+
log_prefix = "+" if is_matched else "-"
81+
logging.getLogger("borg.output.list").info(f"{log_prefix} {remove_surrogates(item.path)}")
7782
if dry_run:
78-
if matcher.match(item.path):
79-
logging.getLogger("borg.output.list").info(f"+ {remove_surrogates(item.path)}")
80-
else:
81-
logging.getLogger("borg.output.list").info(f"- {remove_surrogates(item.path)}")
8283
archive.extract_item(item, dry_run=True, hlm=hlm, pi=pi)
8384
else:
84-
if matcher.match(item.path):
85+
if is_matched:
8586
if stat.S_ISDIR(item.mode):
8687
dirs.append(item)
8788
archive.extract_item(item, stdout=stdout, restore_attrs=False)
88-
else:
89-
archive.extract_item(
90-
item, stdout=stdout, sparse=sparse, hlm=hlm, pi=pi, continue_extraction=continue_extraction
91-
)
89+
else:
90+
archive.extract_item(
91+
item,
92+
stdout=stdout,
93+
sparse=sparse,
94+
hlm=hlm,
95+
pi=pi,
96+
continue_extraction=continue_extraction,
97+
)
9298
except BackupError as e:
9399
self.print_warning_instance(BackupWarning(remove_surrogates(orig_path), e))
94-
95100
if pi:
96101
pi.finish()
102+
# Display excluded items
103+
if excluded_items:
104+
for excluded_item in excluded_items:
105+
logging.getLogger("borg.output.list").info(f"- {remove_surrogates(excluded_item)}")
97106

98107
if not args.dry_run:
99108
pi = ProgressIndicatorPercent(

0 commit comments

Comments
 (0)