diff mbox series

[meta-lts-mixins,wrynose/rust,10/10] ptest-cargo.bbclass: don't follow symlinks when chowning

Message ID c1bbed2a5dfdbf2d5ca734d21d036077ad670bcd.1795997683.git.scott.murray@konsulko.com
State New
Headers show
Series Update to 1.100.0 | expand

Commit Message

Scott Murray Nov. 30, 2026, 12:52 a.m. UTC
From: Trevor Gamblin <tgamblin@baylibre.com>

Use os.lchown() instead of shutil.chown(), as the former follows
symlinks.  os.lchown changes the owner of the link itself.
shutil.chown() didn't add the follow_symlinks option until Python
3.13[1], so we can't just add that argument.

[1]: https://docs.python.org/3/library/shutil.html#shutil.chown

AI-Generated: Uses Claude Opus 5.5
Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
(adapted from oe-core commit c88df9d0ef9b1418d96fea347475c331e54d5dd0)
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
---
 classes-recipe/ptest-cargo.bbclass | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/classes-recipe/ptest-cargo.bbclass b/classes-recipe/ptest-cargo.bbclass
index 0173a2e..340fccf 100644
--- a/classes-recipe/ptest-cargo.bbclass
+++ b/classes-recipe/ptest-cargo.bbclass
@@ -115,12 +115,11 @@  python do_install_ptest_cargo() {
     if not script_exists:
         os.chmod(ptest_script, 0o755)
 
-    # this is chown -R root:root ${D}${PTEST_PATH}
+    # Equivalent to 'chown -R root:root ${D}${PTEST_PATH}, which doesn't follow
+    # symlinks
     for root, dirs, files in os.walk(ptest_dir):
-        for d in dirs:
-            shutil.chown(os.path.join(root, d), "root", "root")
-        for f in files:
-            shutil.chown(os.path.join(root, f), "root", "root")
+        for name in dirs + files:
+            os.lchown(os.path.join(root, name), 0, 0)
 }
 
 do_compile_ptest_cargo[dirs] = "${B}"