From a87e2faa249b8a32e777e08b9a8f360c10452440 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Wed, 27 Sep 2023 18:31:33 +0200 Subject: [PATCH] common: create the compatibility `-imp` symlinks only once The code was trying to create them twice by mistake. The second creation failed, so it was harmless but it unnecessarily polluted `scan.log` like this: ``` [...] >>> 2023-09-27 18:12:14 "ln" "-s" "scan-results.err" "/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp.err" >>> 2023-09-27 18:12:14 "ln" "-s" "scan-results.html" "/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp.html" >>> 2023-09-27 18:12:14 "ln" "-s" "scan-results-summary.txt" "/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp-summary.txt" >>> 2023-09-27 18:12:14 "csgrep --mode=grep --invert-match --event \"internal warning\" --prune-events=1 '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/debug/suppress >>> 2023-09-27 18:12:14 "csgrep --mode=json --invert-match --event \"internal warning\" --prune-events=1 '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/debug/suppress >>> 2023-09-27 18:12:14 "csgrep --mode=evtstat --invert-match --event \"internal warning\" --prune-events=1 '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/debug/suppr >>> 2023-09-27 18:12:14 "\"bash\" \"-c\" \"csgrep '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results.js' --mode=json --checker '^(RESOURCE_LEAK)\\\$' | csgre >>> 2023-09-27 18:12:14 "cslinker --implist '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp.js' '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1 renamed '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp.js' -> '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results.js' >>> 2023-09-27 18:12:14 "csgrep --mode=grep --invert-match --event \"internal warning\" --prune-events=1 '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-a >>> 2023-09-27 18:12:14 "csgrep --mode=json --invert-match --event \"internal warning\" --prune-events=1 '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-a >>> 2023-09-27 18:12:14 "csgrep --mode=evtstat --invert-match --event \"internal warning\" --prune-events=1 '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-result 2 SUPPRESSED_ERROR suppressed_error >>> 2023-09-27 18:12:14 "ln" "-s" "scan-results.err" "/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp.err" ln: failed to create symbolic link '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp.err': File exists >>> 2023-09-27 18:12:14 "ln" "-s" "scan-results.html" "/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp.html" ln: failed to create symbolic link '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp.html': File exists >>> 2023-09-27 18:12:14 "ln" "-s" "scan-results-summary.txt" "/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp-summary.txt" ln: failed to create symbolic link '/tmp/cspodmanfx586tbu/prom-label-proxy-container-v4.1.8-201907241243/scan-results-imp-summary.txt': File exists [...] ``` Related: https://issues.redhat.com/browse/OSH-289 --- py/common/results.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/py/common/results.py b/py/common/results.py index 2c1820f..c4a1a69 100644 --- a/py/common/results.py +++ b/py/common/results.py @@ -331,12 +331,6 @@ def finalize_results(js_file, results, props): # generate *-all{.err,.html,-summary.txt} transform_results(all_js_file, results) - # create `-imp` symlinks for compatibility - for suffix in [".err", ".html", "-summary.txt"]: - src = f"scan-results{suffix}" - dst = os.path.join(results.resdir, f"scan-results-imp{suffix}") - results.exec_cmd(["ln", "-s", src, dst]) - (err_file, _) = transform_results(js_file, results) if props.print_defects: @@ -366,6 +360,13 @@ def apply_result_filters(props, results, supp_filters=[]): finalize_results(js_supp, results, props) finalize_results(js_file, results, props) + # create `-imp` symlinks for compatibility (if important defects were filtered) + if props.imp_checker_set: + for suffix in [".err", ".html", "-summary.txt"]: + src = f"scan-results{suffix}" + dst = os.path.join(results.resdir, f"scan-results-imp{suffix}") + results.exec_cmd(["ln", "-s", src, dst]) + def handle_known_fp_list(props, results): """Update props.result_filters based on props.known_false_positives"""