@@ -101,16 +101,20 @@ class ExtractionConfig:
101101 verbose : int = 1
102102 progress_reporter : Type [ProgressReporter ] = NullProgressReporter
103103
104- def get_extract_dir_for (self , path : Path ) -> Path :
105- """Return extraction dir under root with the name of path ."""
104+ def _get_output_path (self , path : Path ) -> Path :
105+ """Return path under extract root ."""
106106 try :
107107 relative_path = path .relative_to (self .extract_root )
108108 except ValueError :
109109 # path is not inside root, i.e. it is an input file
110110 relative_path = Path (path .name )
111- extract_name = path .name + self .extract_suffix
112- extract_dir = self .extract_root / relative_path .with_name (extract_name )
113- return extract_dir .expanduser ().resolve ()
111+ return (self .extract_root / relative_path ).expanduser ().resolve ()
112+
113+ def get_extract_dir_for (self , path : Path ) -> Path :
114+ return self ._get_output_path (path .with_name (path .name + self .extract_suffix ))
115+
116+ def get_carve_dir_for (self , path : Path ) -> Path :
117+ return self ._get_output_path (path .with_name (path .name + self .carve_suffix ))
114118
115119
116120@terminate_gracefully
@@ -131,6 +135,11 @@ def process_file(
131135 logger .info ("Removing extract dir" , path = extract_dir )
132136 shutil .rmtree (extract_dir )
133137
138+ carve_dir = config .get_carve_dir_for (input_path )
139+ if config .force_extract and carve_dir .exists ():
140+ logger .info ("Removing carve dir" , path = carve_dir )
141+ shutil .rmtree (carve_dir )
142+
134143 if not prepare_report_file (config , report_file ):
135144 logger .error (
136145 "File not processed, as report could not be written" , file = input_path
@@ -139,7 +148,7 @@ def process_file(
139148
140149 process_result = _process_task (config , task )
141150
142- if not config .skip_extraction :
151+ if not config .skip_extraction and not carve_dir . exists () :
143152 # ensure that the root extraction directory is created even for empty extractions
144153 extract_dir .mkdir (parents = True , exist_ok = True )
145154
0 commit comments