diff mbox series

devtool: handle symlinks in source tree cleanup

Message ID 20260826084231.55333-1-jaipaul.cheernam@est.tech
State New
Headers show
Series devtool: handle symlinks in source tree cleanup | expand

Commit Message

Jaipaul Cheernam Aug. 26, 2026, 8:42 a.m. UTC
- 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.

Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
---
 scripts/lib/devtool/upgrade.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/scripts/lib/devtool/upgrade.py b/scripts/lib/devtool/upgrade.py
index 523acf4250..5c2e6ebd46 100644
--- a/scripts/lib/devtool/upgrade.py
+++ b/scripts/lib/devtool/upgrade.py
@@ -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)