|
20 | 20 | # ScanCode.io is a free software code scanning tool from nexB Inc. and others. |
21 | 21 | # Visit https://github.com/aboutcode-org/scancode.io for support and download. |
22 | 22 |
|
| 23 | +import shutil |
| 24 | +from pathlib import Path |
| 25 | + |
23 | 26 | from scanpipe.pipelines.deploy_to_develop import DeployToDevelop |
24 | 27 | from scanpipe.pipelines.scan_codebase import ScanCodebase |
25 | 28 | from scanpipe.pipelines.scan_single_package import ScanSinglePackage |
@@ -51,6 +54,7 @@ def steps(cls): |
51 | 54 | cls.fetch_inputs, |
52 | 55 | cls.collect_input_info, |
53 | 56 | cls.extract_input_to_codebase_directory, |
| 57 | + cls.collect_and_create_codebase_resources, |
54 | 58 | cls.run_scan, |
55 | 59 | cls.load_inventory_from_toolkit_scan, |
56 | 60 | cls.add_from_to_tag, |
@@ -95,17 +99,26 @@ def collect_input_info(self): |
95 | 99 | def extract_input_to_codebase_directory(self): |
96 | 100 | """Extract input to project codebase/ directory.""" |
97 | 101 | if self.input_path: |
98 | | - nix.extract_nar_archive( |
| 102 | + extracted_path = nix.extract_nar_archive( |
99 | 103 | self.input_path, self.project.codebase_path, self.output_format |
100 | 104 | ) |
101 | 105 |
|
102 | | - # Reload the project env post-extraction as the scancode-config.yml file |
103 | | - # may be located in one of the extracted archives. |
| 106 | + to_dir = Path(self.project.codebase_path) / "to" |
| 107 | + # If the extraction failed (returned "") or we found it was empty |
| 108 | + if not extracted_path or (to_dir.exists() and not list(to_dir.rglob("*"))): |
| 109 | + if to_dir.exists(): |
| 110 | + shutil.rmtree(to_dir) |
| 111 | + self.d2d_enable = False |
| 112 | + self.project.add_error( |
| 113 | + "Failed to extract NAR archive, D2D scan disabled." |
| 114 | + ) |
| 115 | + |
104 | 116 | self.env = self.project.get_env() |
105 | 117 |
|
106 | 118 | def add_from_to_tag(self): |
107 | 119 | """Update 'from' and 'to' tag to resources based on their path.""" |
108 | | - d2d.update_from_to_tag(self.project) |
| 120 | + if self.d2d_enable: |
| 121 | + d2d.update_from_to_tag(self.project) |
109 | 122 |
|
110 | 123 | def d2d_steps(self): |
111 | 124 | """ |
|
0 commit comments