Skip to contentSkip to conversation

devtool: handle symlinks in source tree cleanup

PATCH New Jaipaul Cheernam 1 participant 1 message Aug 26

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devtool: handle symlinks in source tree cleanup

- os.path.isdir() follows symlinks, so symlinks to directories were passed to shutil.rmtree() which raises:

File "scripts/lib/devtool/upgrade.py", line 280, in _extract_new_source
shutil.rmtree(itempath)
File "/usr/lib/python3.12/shutil.py", line 802, in rmtree
onexc(os.path.islink, path, err)
File "/usr/lib/python3.12/shutil.py", line 800, in rmtree
raise OSError("Cannot call rmtree on a symbolic link")

- Same issue reported on AUH while upgrading for man-pages

- Add check for symlinks first and use os.remove() on them.

---
 scripts/lib/devtool/upgrade.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/lib/devtool/upgrade.py +3 -1
index 523acf4250..5c2e6ebd46 100644
@@ -276,7 +276,9 @@ def _extract_new_source(newpv, srctree, no_patch, srcrev, srcbranch, branch, kee
             if item in ['.git', 'oe-local-files']:
                 continue
             itempath = os.path.join(srctree, item)
-            if os.path.isdir(itempath):
+            if os.path.islink(itempath):
+                os.remove(itempath)
+            elif os.path.isdir(itempath):
                 shutil.rmtree(itempath)
             else:
                 os.remove(itempath)