@@ -65,6 +65,17 @@ class ExtractionConfig:
6565 extract_suffix : str = "_extract"
6666 handlers : Handlers = BUILTIN_HANDLERS
6767
68+ def get_extract_dir_for (self , path : Path ) -> Path :
69+ """Extraction dir under root with the name of path."""
70+ try :
71+ relative_path = path .relative_to (self .extract_root )
72+ except ValueError :
73+ # path is not inside root, i.e. it is an input file
74+ relative_path = Path (path .name )
75+ extract_name = path .name + self .extract_suffix
76+ extract_dir = self .extract_root / relative_path .with_name (extract_name )
77+ return extract_dir .expanduser ().resolve ()
78+
6879
6980@terminate_gracefully
7081def process_file (config : ExtractionConfig , path : Path ) -> ProcessResult :
@@ -104,7 +115,7 @@ def process_result(pool, result):
104115def check_extract_directory (task : Task , config : ExtractionConfig ):
105116 errors = []
106117
107- extract_dir = get_extract_dir_for_input ( config , task .path )
118+ extract_dir = config . get_extract_dir_for ( task .path )
108119 if extract_dir .exists ():
109120 if config .force_extract :
110121 shutil .rmtree (extract_dir )
@@ -198,7 +209,7 @@ def __init__(
198209 self .size = size
199210 self .result = result
200211
201- self .carve_dir = get_extract_dir_for_input ( config , self .task .path )
212+ self .carve_dir = config . get_extract_dir_for ( self .task .path )
202213
203214 def process (self ):
204215 logger .debug ("Processing file" , path = self .task .path , size = self .size )
@@ -285,18 +296,6 @@ def _extract_chunk(self, file, chunk: ValidChunk):
285296 )
286297
287298
288- def get_extract_dir_for_input (config : ExtractionConfig , path : Path ) -> Path :
289- """Extraction dir under root with the name of path."""
290- try :
291- relative_path = path .relative_to (config .extract_root )
292- except ValueError :
293- # path is not inside root, i.e. it is an input file
294- relative_path = Path (path .name )
295- extract_name = path .name + config .extract_suffix
296- extract_dir = config .extract_root / relative_path .with_name (extract_name )
297- return extract_dir .expanduser ().resolve ()
298-
299-
300299def remove_inner_chunks (chunks : List [ValidChunk ]) -> List [ValidChunk ]:
301300 """Remove all chunks from the list which are within another bigger chunks."""
302301 if not chunks :
0 commit comments