Skip to content

Commit e4e70a2

Browse files
committed
Better error handling and add back the missing "collect_and_create_codebase_resources" #1938
Signed-off-by: Chin Yeung Li <tli@nexb.com>
1 parent 7fe1177 commit e4e70a2

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

scanpipe/pipelines/scan_nix_package.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
2121
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222

23+
import shutil
24+
from pathlib import Path
25+
2326
from scanpipe.pipelines.deploy_to_develop import DeployToDevelop
2427
from scanpipe.pipelines.scan_codebase import ScanCodebase
2528
from scanpipe.pipelines.scan_single_package import ScanSinglePackage
@@ -51,6 +54,7 @@ def steps(cls):
5154
cls.fetch_inputs,
5255
cls.collect_input_info,
5356
cls.extract_input_to_codebase_directory,
57+
cls.collect_and_create_codebase_resources,
5458
cls.run_scan,
5559
cls.load_inventory_from_toolkit_scan,
5660
cls.add_from_to_tag,
@@ -95,17 +99,26 @@ def collect_input_info(self):
9599
def extract_input_to_codebase_directory(self):
96100
"""Extract input to project codebase/ directory."""
97101
if self.input_path:
98-
nix.extract_nar_archive(
102+
extracted_path = nix.extract_nar_archive(
99103
self.input_path, self.project.codebase_path, self.output_format
100104
)
101105

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+
104116
self.env = self.project.get_env()
105117

106118
def add_from_to_tag(self):
107119
"""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)
109122

110123
def d2d_steps(self):
111124
"""

0 commit comments

Comments
 (0)