From patchwork Thu Dec 3 10:18:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Leferenz via B4 Relay X-Patchwork-Id: 107098 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.10987.1796293394939147459 for ; Thu, 03 Dec 2026 02:23:15 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20260515 header.b=LhRzHFKQ; spf=pass (domain: kernel.org, ip: 172.234.252.31, mailfrom: devnull+florian.leferenz.wabtec.com@kernel.org) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 57CBE43DBD; Thu, 3 Dec 2026 10:18:11 +0000 (UTC) Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796293091; b=i/FkaGdY0Em7QEH6X8kAZhw0hxKkJNe/cVCehv+h9QdfEo/EGDRfzTCUuiUB8hHbZH9E IkG0lnbmsBufCwQ9JUw3db0gDb00VWYFEkpd+RgyZE95eqX7TkJsfqCKu0qmpARUQwymU STKdCZSuK9iCkKiMbziOis45Of+dB3rTLZTCM7GufOqg84zfKy06tcg7N1Fy8CevoQ0sa CIj9kgQTECi2uqA1lWvDm5VYI/qbct7Dz+W27L+dGugszCe62Wooy56ytG09j2iofyXwV RIxVgwEUqv8Us/RXgvvCzx1o9+i3HN4l4QFMtbE0KvttNIqQr+n4MhUH3YTR2IYnMJw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796293091; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=mNs6NKE3PZdNrS20/oN4zYIk6rRotnEit/36qhIg/dM=; b=XMSkwn0eQiWB/yyhdsvSpJKajjDnHlASOFKfGXXtYv4OXIvZ6/YoHOZfzCVYiz2z4NYz JFmBv4KBhWXymh8xqDPBKZqeyFLdtqm85czr7NmndHzbM/dOtb0e/b0UA+4uA2VR7XHaQ Zoo1kt21YLT5W/dEUrcJUmAQD7/f/bAdHBOOnTq/yTwtcKLVG/9K8X1nBuoZe3x/fmA2m jWAy294Gda7Gr4a9jMlvEk3ly2FhFZNngE0Ey6jlJccN/GKwKuVgTvOWJhF2AOHnE7DtI p6NKfDUPDxLtwQbEpvESX5Qo5XDLeloXHrVdGt2TgTFmHZUehsLhNaOJQ+QkDnrojXA== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id B5AAF1F000C1; Thu, 3 Dec 2026 10:18:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796293091; bh=mNs6NKE3PZdNrS20/oN4zYIk6rRotnEit/36qhIg/dM=; h=From:Date:Subject:To:Cc:Reply-To; b=LhRzHFKQZE7CN0EqCnaX0UqI3WRvXdAbaDV3coWHvFnR9YdTClF7K2ne3f6dukcNN Jyyquk617T2W7+5jbAqGn/WPHFEJDhJsE/4qG1VF7ThLmtMpGi4LaMBtaweuK8Awco HthD24y0V/pK3Ioa5vJLbTVBMf9PhL6/PAMPUkeGQt5Tu5BpeoOgSrok+MSdRJFzek AvQJhwzjygf/N8tS3Q1sSWBpBr4QqMtbyhqm5a3LDL1EFeFD/iqhTsMO6xTfJBbFxB 6Il9f0mhVNDNDVvoBctTLnLqyQ/Bw5ac3m4OstnHUj9HNq2YEdsiAv8RMdUH6dJ1iM 7dElcwdXnxbYQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 15E374F8DB; Thu, 3 Dec 2026 10:18:10 +0000 (UTC) From: Florian Leferenz via B4 Relay Date: Thu, 03 Dec 2026 11:18:05 +0100 Subject: [PATCH] oe/path: don't follow symlinks in copyhardlinktree()'s hardlink test MIME-Version: 1.0 Message-Id: <20261203-fix-copyhardlinktree-dangling-symlink-v1-1-46c4802937ae@wabtec.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yWNSw6CQBBEr0J6bSfMkBj1KsbFfApoPwOZASMh3 N1Gl69S9WqlgiwodKlWynhLkSEpmENFoXepA0tUJlvbo7F1w618OAzj0rscn5IeUwY4alOh47K 89pAb720LZ4DTmdQ1Zujw93O9/bnM/o4w7XLati8tANwpiQAAAA== X-Change-ID: 20261203-fix-copyhardlinktree-dangling-symlink-3bb2fea1ee89 To: openembedded-core@lists.openembedded.org Cc: Florian Leferenz X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796293089; l=3242; i=florian.leferenz@wabtec.com; s=20261203; h=from:subject:message-id; bh=XKTrylUAmrHPxckmNj23+Hnh34uoDQkbSJYfstydypM=; b=ej4JPhAXGCO6pYTC3mYRb+0KGurDhJLAaWc/SyKsVwVQ4HyeTCt6pA4HU6GxpYy1zvAFctJpW kAiLNTYWV1kAqAg3Hi+WlsHXJrxokfqJFfQTvfj/0JITX7vHku5gXjP X-Developer-Key: i=florian.leferenz@wabtec.com; a=ed25519; pk=nb8d0MJNXLzEKULxD89J2Vd0ntxV70/bRdfLv3XNg1U= X-Endpoint-Received: by B4 Relay for florian.leferenz@wabtec.com/20261203 with auth_id=1731 X-Original-From: Florian Leferenz Reply-To: florian.leferenz@wabtec.com List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Thu, 03 Dec 2026 10:26:13 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251882 From: Florian Leferenz copyhardlinktree() hardlinks the first file os.walk() returns to decide between hardlinking and a full tar copy. os.link() follows symlinks by default, so if that entry is a dangling symlink (e.g. var/lock -> /run/lock in a rootfs) the test fails with ENOENT and the whole tree is copied with tar. Which entry comes first depends on the directory order of the host filesystem, so the result differs between build hosts. Link the entry itself instead and add an oe-selftest case for it. The standalone wic carries a copy of this code and gets the same fix. AI-Generated: Uses GitHub Copilot Signed-off-by: Florian Leferenz --- oe/path: fix copyhardlinktree() hardlink test with dangling symlinks --- meta/lib/oe/path.py | 2 +- meta/lib/oeqa/selftest/cases/liboe.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) --- base-commit: 73216413e23c280ce9accd5e740134b4084c2851 change-id: 20261203-fix-copyhardlinktree-dangling-symlink-3bb2fea1ee89 Best regards, diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py index 5122fcb08e..69199c87da 100644 --- a/meta/lib/oe/path.py +++ b/meta/lib/oe/path.py @@ -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: diff --git a/meta/lib/oeqa/selftest/cases/liboe.py b/meta/lib/oeqa/selftest/cases/liboe.py index 96969da161..3930a31c6d 100644 --- a/meta/lib/oeqa/selftest/cases/liboe.py +++ b/meta/lib/oeqa/selftest/cases/liboe.py @@ -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):