Skip to content

Commit 2b1f432

Browse files
committed
Fix a bug where output is not generated without -o
1 parent 4d7eeb9 commit 2b1f432

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/fosslight_scanner/common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@
1515

1616

1717
def copy_file(source, destination):
18+
copied_file = ""
1819
try:
1920
copy(source, destination)
21+
if os.path.isdir(destination):
22+
copied_file = os.path.join(destination, os.path.basename(source))
23+
else:
24+
copied_file = destination
2025
except Exception as ex:
2126
logger.debug(f"Failed to copy {source} to {destination}: {ex}")
27+
return False, copied_file
28+
else:
29+
return True, copied_file
2230

2331

2432
def run_analysis(path_to_run, params, func, str_run_start, output, exe_path):

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
101101
create_csv = False
102102
final_excel_dir = output_path
103103
success = True
104+
temp_output_fiiles = []
104105
if not remove_src_data:
105106
success, final_excel_dir, result_log = init(output_path)
106107

@@ -129,7 +130,9 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
129130
-1, reuse_lint,
130131
abs_path, "", False,
131132
output_reuse)
132-
copy_file(output_reuse, output_path)
133+
success_file, copied_file = copy_file(output_reuse, output_path)
134+
if success_file:
135+
temp_output_fiiles.append(copied_file)
133136

134137
if run_src:
135138
try:
@@ -161,7 +164,9 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
161164
os.path.join(_output_dir, output_files["BIN"]),
162165
"", db_url)
163166
if success:
164-
copy_file(os.path.join(_output_dir, output_files["BIN_TXT"]), output_path)
167+
success_file, copied_file = copy_file(os.path.join(_output_dir, output_files["BIN_TXT"]), output_path)
168+
if success_file:
169+
temp_output_fiiles.append(copied_file)
165170

166171
if run_dep:
167172
run_dependency(src_path, os.path.join(_output_dir, output_files["DEP"]), dep_arguments)
@@ -180,7 +185,8 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
180185
success, output_files = merge_excels(_output_dir, final_report, create_csv)
181186

182187
if success and output_files:
183-
result_log["Output File"] = output_files.split(",")
188+
temp_output_fiiles.extend(output_files.split(","))
189+
result_log["Output File"] = temp_output_fiiles
184190
else:
185191
logger.error(f"Fail to generate a result file. : {output_files}")
186192

@@ -251,9 +257,11 @@ def init(output_path=""):
251257

252258
def run_main(mode, src_path, dep_arguments, output_file_or_dir, file_format, url_to_analyze, db_url,
253259
hide_progressbar=False, keep_raw_data=False, num_cores=-1):
260+
global _executed_path
261+
254262
output_file = ""
255-
output_path = _executed_path
256263
default_oss_name = ""
264+
_executed_path = os.getcwd()
257265
try:
258266
success, msg, output_path, output_file, output_extension = check_output_format(output_file_or_dir, file_format)
259267
if not success:
@@ -265,6 +273,8 @@ def run_main(mode, src_path, dep_arguments, output_file_or_dir, file_format, url
265273
run_dep = False
266274
run_reuse = False
267275
remove_downloaded_source = False
276+
if output_path == "":
277+
output_path = _executed_path
268278

269279
if src_path == "" and url_to_analyze == "":
270280
src_path, dep_arguments, url_to_analyze = get_input_mode()

0 commit comments

Comments
 (0)