@@ -156,7 +156,7 @@ def copyhardlinktree(src, dst):
if testfile is not None:
try:
- os.link(testfile, os.path.join(dst, 'testfile'))
+ os.link(testfile, os.path.join(dst, 'testfile'), follow_symlinks=False)
os.unlink(os.path.join(dst, 'testfile'))
canhard = True
except Exception as e:
@@ -106,6 +106,28 @@ class CopyTreeTests(OESelftestTestCase):
oe.path.remove(testloc)
+ def test_copy_hardlink_tree_dangling_symlink(self):
+ """
+ Summary: oe.path.copyhardlinktree() should still hardlink when the
+ first entry os.walk() returns is a dangling symlink
+ Expected: the regular file in dst is a hardlink of the one in src
+ Product: OE-Core
+ """
+ with tempfile.TemporaryDirectory(prefix="oeqa-copyhardlinktree-") as testloc:
+ src = oe.path.join(testloc, 'src')
+ dst = oe.path.join(testloc, 'dst')
+ bb.utils.mkdirhier(oe.path.join(src, 'sub'))
+ # Like var/lock -> /run/lock in a target rootfs
+ os.symlink('/nonexistent/target', oe.path.join(src, 'dangling'))
+ open(oe.path.join(src, 'sub', 'file'), 'w+b').close()
+
+ oe.path.copyhardlinktree(src, dst)
+
+ self.assertTrue(os.path.samefile(oe.path.join(src, 'sub', 'file'),
+ oe.path.join(dst, 'sub', 'file')),
+ "File in dst was copied instead of hardlinked")
+ self.assertEqual(os.readlink(oe.path.join(dst, 'dangling')), '/nonexistent/target')
+
class SubprocessTests(OESelftestTestCase):
def test_subprocess_tweak(self):