2020from .models import ExtractError , File , Task , TaskResult , UnknownChunk , ValidChunk
2121from .pool import make_pool
2222from .report import (
23- ExtractDirectoriesExistReport ,
23+ ExtractDirectoryExistsReport ,
2424 FileMagicReport ,
25+ Report ,
2526 StatReport ,
2627 UnknownError ,
2728)
@@ -59,24 +60,34 @@ class ExtractionConfig:
5960
6061
6162@terminate_gracefully
62- def process_files (config : ExtractionConfig , * paths : Path ) -> List [Report ]:
63- existing_extract_dirs = get_existing_extract_dirs (config , paths )
63+ def process_files (config : ExtractionConfig , path : Path ) -> List [Report ]:
64+ task = Task (
65+ path = path ,
66+ depth = 0 ,
67+ )
6468
65- if config .force_extract :
66- for d in existing_extract_dirs :
67- shutil .rmtree (d )
68- elif existing_extract_dirs :
69- report = ExtractDirectoriesExistReport (paths = existing_extract_dirs )
70- logger .error ("Extraction directories already exist" , ** report .asdict ())
71- return [report ]
69+ errors = check_extract_directory (task , config )
70+ if errors :
71+ return errors
7272
73- all_reports = []
74- for path in paths :
75- report = _process_one_file (config , path )
76- all_reports .extend (report )
73+ result = _process_one_file (config , task )
74+
75+ return result
7776
78- return all_reports
7977
78+ def check_extract_directory (task : Task , config : ExtractionConfig ):
79+ errors = []
80+
81+ extract_dir = get_extract_dir_for_input (config , task .path )
82+ if extract_dir .exists ():
83+ if config .force_extract :
84+ shutil .rmtree (extract_dir )
85+ else :
86+ report = ExtractDirectoryExistsReport (path = extract_dir )
87+ logger .error ("Extraction directory already exist" , ** report .asdict ())
88+ errors .append (report )
89+
90+ return errors
8091
8192def get_existing_extract_dirs (
8293 config : ExtractionConfig , paths : Iterable [Path ]
@@ -95,12 +106,7 @@ def get_existing_extract_dirs(
95106 return extract_dirs
96107
97108
98- def _process_one_file (config : ExtractionConfig , path : Path ) -> List [Report ]:
99- root_task = Task (
100- path = path ,
101- depth = 0 ,
102- )
103-
109+ def _process_one_file (config : ExtractionConfig , root_task : Task ) -> List [Report ]:
104110 processor = Processor (config )
105111 all_reports = []
106112
0 commit comments