diff options
author | Ernst Sjöstrand <ernstp@gmail.com> | 2022-05-24 13:50:20 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-05-27 23:50:47 +0100 |
commit | fd5a40c0132b14d28190fcbeab02469340636cde (patch) | |
tree | 146765e7387437a3a952e132d020b5fcc2299757 /meta/classes/cve-check.bbclass | |
parent | d595363c318f56de5fb0d607468a8a026f440fcd (diff) | |
download | poky-fd5a40c0132b14d28190fcbeab02469340636cde.tar.gz |
cve-check: Add helper for symlink handling
(From OE-Core rev: 5046d54df2c3057be2afa4143a2833183fca0d67)
Signed-off-by: Ernst Sjöstrand <ernstp@gmail.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/cve-check.bbclass')
-rw-r--r-- | meta/classes/cve-check.bbclass | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/meta/classes/cve-check.bbclass b/meta/classes/cve-check.bbclass index 3729d9cba8..0ab7ec7ae6 100644 --- a/meta/classes/cve-check.bbclass +++ b/meta/classes/cve-check.bbclass | |||
@@ -79,6 +79,12 @@ CVE_CHECK_LAYER_INCLUDELIST ??= "" | |||
79 | # set to "alphabetical" for version using single alphabetical character as increment release | 79 | # set to "alphabetical" for version using single alphabetical character as increment release |
80 | CVE_VERSION_SUFFIX ??= "" | 80 | CVE_VERSION_SUFFIX ??= "" |
81 | 81 | ||
82 | def update_symlinks(target_path, link_path): | ||
83 | if link_path != target_path and os.path.exists(target_path): | ||
84 | if os.path.exists(os.path.realpath(link_path)): | ||
85 | os.remove(link_path) | ||
86 | os.symlink(os.path.basename(target_path), link_path) | ||
87 | |||
82 | def generate_json_report(d, out_path, link_path): | 88 | def generate_json_report(d, out_path, link_path): |
83 | if os.path.exists(d.getVar("CVE_CHECK_SUMMARY_INDEX_PATH")): | 89 | if os.path.exists(d.getVar("CVE_CHECK_SUMMARY_INDEX_PATH")): |
84 | import json | 90 | import json |
@@ -98,10 +104,7 @@ def generate_json_report(d, out_path, link_path): | |||
98 | with open(out_path, "w") as f: | 104 | with open(out_path, "w") as f: |
99 | json.dump(summary, f, indent=2) | 105 | json.dump(summary, f, indent=2) |
100 | 106 | ||
101 | if link_path != out_path: | 107 | update_symlinks(out_path, link_path) |
102 | if os.path.exists(os.path.realpath(link_path)): | ||
103 | os.remove(link_path) | ||
104 | os.symlink(os.path.basename(out_path), link_path) | ||
105 | 108 | ||
106 | python cve_save_summary_handler () { | 109 | python cve_save_summary_handler () { |
107 | import shutil | 110 | import shutil |
@@ -118,14 +121,9 @@ python cve_save_summary_handler () { | |||
118 | 121 | ||
119 | if os.path.exists(cve_tmp_file): | 122 | if os.path.exists(cve_tmp_file): |
120 | shutil.copyfile(cve_tmp_file, cve_summary_file) | 123 | shutil.copyfile(cve_tmp_file, cve_summary_file) |
121 | 124 | cvefile_link = os.path.join(cvelogpath, cve_summary_name) | |
122 | if cve_summary_file and os.path.exists(cve_summary_file): | 125 | update_symlinks(cve_summary_file, cvefile_link) |
123 | cvefile_link = os.path.join(cvelogpath, cve_summary_name) | 126 | bb.plain("Complete CVE report summary created at: %s" % cvefile_link) |
124 | # if the paths are the same don't create the link | ||
125 | if cvefile_link != cve_summary_file: | ||
126 | if os.path.exists(os.path.realpath(cvefile_link)): | ||
127 | os.remove(cvefile_link) | ||
128 | os.symlink(os.path.basename(cve_summary_file), cvefile_link) | ||
129 | 127 | ||
130 | if d.getVar("CVE_CHECK_FORMAT_JSON") == "1": | 128 | if d.getVar("CVE_CHECK_FORMAT_JSON") == "1": |
131 | json_summary_link_name = os.path.join(cvelogpath, d.getVar("CVE_CHECK_SUMMARY_FILE_NAME_JSON")) | 129 | json_summary_link_name = os.path.join(cvelogpath, d.getVar("CVE_CHECK_SUMMARY_FILE_NAME_JSON")) |
@@ -198,15 +196,9 @@ python cve_check_write_rootfs_manifest () { | |||
198 | bb.utils.mkdirhier(os.path.dirname(manifest_name)) | 196 | bb.utils.mkdirhier(os.path.dirname(manifest_name)) |
199 | shutil.copyfile(cve_tmp_file, manifest_name) | 197 | shutil.copyfile(cve_tmp_file, manifest_name) |
200 | 198 | ||
201 | if manifest_name and os.path.exists(manifest_name): | 199 | manifest_link = os.path.join(deploy_dir, "%s.cve" % link_name) |
202 | manifest_link = os.path.join(deploy_dir, "%s.cve" % link_name) | 200 | update_symlinks(manifest_name, manifest_link) |
203 | # if they are the same don't create the link | 201 | bb.plain("Image CVE report stored in: %s" % manifest_name) |
204 | if manifest_link != manifest_name: | ||
205 | # If we already have another manifest, update symlinks | ||
206 | if os.path.exists(os.path.realpath(manifest_link)): | ||
207 | os.remove(manifest_link) | ||
208 | os.symlink(os.path.basename(manifest_name), manifest_link) | ||
209 | bb.plain("Image CVE report stored in: %s" % manifest_name) | ||
210 | 202 | ||
211 | if d.getVar("CVE_CHECK_FORMAT_JSON") == "1": | 203 | if d.getVar("CVE_CHECK_FORMAT_JSON") == "1": |
212 | link_path = os.path.join(deploy_dir, "%s.json" % link_name) | 204 | link_path = os.path.join(deploy_dir, "%s.json" % link_name) |