[master][kirkstone][PATCH 1/5] lib/oe/cve_check: refactor update_symlinks with safer version


Davide Gardenal
 

Now update_symlinks has more checks to prevent unwanted exception.
It returns False if the link is not created/updated, True otherwise.

Signed-off-by: Davide Gardenal <davide.gardenal@...>
---
meta/lib/oe/cve_check.py | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/meta/lib/oe/cve_check.py b/meta/lib/oe/cve_check.py
index aa06497727..688693520e 100644
--- a/meta/lib/oe/cve_check.py
+++ b/meta/lib/oe/cve_check.py
@@ -169,7 +169,17 @@ def update_symlinks(target_path, link_path):
Update a symbolic link link_path to point to target_path.
Remove the link and recreate it if exist and is different.
"""
- if link_path != target_path and os.path.exists(target_path):
- if os.path.exists(os.path.realpath(link_path)):
- os.remove(link_path)
- os.symlink(os.path.basename(target_path), link_path)
+ import os
+
+ if target_path == link_path or \
+ target_path is None or \
+ link_path is None or \
+ not os.path.exists(target_path):
+
+ return False
+
+ if os.path.lexists(link_path):
+ os.remove(link_path)
+
+ os.symlink(target_path, link_path)
+ return True
--
2.34.1

Join {openembedded-core@lists.openembedded.org to automatically receive all group messages.