@@ -38,7 +38,6 @@ def do_extract(self, args, repository, manifest, archive):
38
38
matcher = build_matcher (args .patterns , args .paths )
39
39
40
40
progress = args .progress
41
- output_list = args .output_list
42
41
dry_run = args .dry_run
43
42
stdout = args .stdout
44
43
sparse = args .sparse
@@ -48,6 +47,7 @@ def do_extract(self, args, repository, manifest, archive):
48
47
hlm = HardLinkManager (id_type = bytes , info_type = str ) # hlid -> path
49
48
50
49
filter = build_filter (matcher , strip_components )
50
+
51
51
if progress :
52
52
pi = ProgressIndicatorPercent (msg = "%5.1f%% Extracting: %s" , step = 0.1 , msgid = "extract" )
53
53
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):
56
56
else :
57
57
pi = None
58
58
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 )
60
64
61
- for item in all_items :
65
+ for item in archive . iter_items ( filter , preload = True ) :
62
66
orig_path = item .path
63
67
if strip_components :
64
68
item .path = os .sep .join (orig_path .split (os .sep )[strip_components :])
@@ -71,29 +75,34 @@ def do_extract(self, args, repository, manifest, archive):
71
75
except BackupError as e :
72
76
self .print_warning_instance (BackupWarning (remove_surrogates (dir_item .path ), e ))
73
77
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 )
76
79
try :
80
+ log_prefix = "+" if is_matched else "-"
81
+ logging .getLogger ("borg.output.list" ).info (f"{ log_prefix } { remove_surrogates (item .path )} " )
77
82
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 )} " )
82
83
archive .extract_item (item , dry_run = True , hlm = hlm , pi = pi )
83
84
else :
84
- if matcher . match ( item . path ) :
85
+ if is_matched :
85
86
if stat .S_ISDIR (item .mode ):
86
87
dirs .append (item )
87
88
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
+ )
92
98
except BackupError as e :
93
99
self .print_warning_instance (BackupWarning (remove_surrogates (orig_path ), e ))
94
-
95
100
if pi :
96
101
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 )} " )
97
106
98
107
if not args .dry_run :
99
108
pi = ProgressIndicatorPercent (
0 commit comments