diff mbox series

[6/6,v2] ptest-cargo.bbclass: don't follow symlinks when chowning

Message ID 20261125160821.3028875-7-tgamblin@baylibre.com
State Under Review
Headers show
Series add hyperfine recipe, improve ptest-cargo.bbclass | expand

Commit Message

Trevor Gamblin Nov. 25, 2026, 4:08 p.m. UTC
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>
---
 meta/classes-recipe/ptest-cargo.bbclass | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/ptest-cargo.bbclass b/meta/classes-recipe/ptest-cargo.bbclass
index cc82ea320b..8f4f003a9a 100644
--- a/meta/classes-recipe/ptest-cargo.bbclass
+++ b/meta/classes-recipe/ptest-cargo.bbclass
@@ -117,12 +117,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}"