From patchwork Thu Dec 3 08:32:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leferenz, Florian" X-Patchwork-Id: 107096 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.9795.1796286765671355465 for ; Thu, 03 Dec 2026 00:32:45 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20260515 header.b=BYdmH4OJ; 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 957654032A; Thu, 3 Dec 2026 08:32:44 +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=1796286764; b=BRJ+PauSolxq7eimZWrntdxk2cZ4lAPMgM7uO7uSq+ajvdh9nhsroZAABi/JaxMK2HIM C5xz4tLDdo2zpgvDx0Q6kCSX+wCZxABsFH0sHqMkCoCT0irsSw7bqh9nmmyxb5MIXcTS5 yEffuRuHX7HSJszdPcFfU9Zz7Ocd7suxkIt8fqhsFio/JDIFqMYzB3s3Ps0+P+BKx48/M 8jodGPZOOdSlODg6Wz3ijrxVmVsJHamU919l+piBiTVMaiJKbhFyf0A87z5obplKRv/4R XnCMmXkfXBXydN3qDEvSyfoIFoEnfGmw/+2XzS8YxbXWqj/xjbl3gxvkYRr74pvC7bw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796286764; 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=xoTyhW0djNwKRDxiLhicop9tLOKE4vWtNfSFRVtxNnk=; b=fmCOdwY1I9MzGq8UtvUknFe7YhFlcQQWX0umbBb25JRRlQ9WeSRp2t5NdNf6wkgZPQNS CMdNhSNGt3GRwnVIJnW1Fcmc9e6awsNAwLV3eUyJV7hDv+uKV2nGvMctxYoBUEugkKVR8 sXy+oq+SnOV29gzvgMhpscdtDwe5ueliv2QgtWmxaooRr1BdKHmhDxkcmOvW/GglOYL6x y8IbSdup9GSeIAN1+Sp12UktznlH4/A8SvT/Ja5UlFWn//shBkgLk9JCexU33m5O0UbiJ dXTomwUofTDYQetTmJ3TlvUnG0PSbVtaHp51S2etHO0fe0w+iPp2AWUt+DqKoQf36+Q== 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 8EC321F000C1; Thu, 3 Dec 2026 08:32:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796286764; bh=xoTyhW0djNwKRDxiLhicop9tLOKE4vWtNfSFRVtxNnk=; h=From:Date:Subject:To:Cc:Reply-To; b=BYdmH4OJ6tBMEzmGJ1nTDWWiuWvSc3XolsxR4tzSeD4B+BIRHSIvZyYcsBEI0FZ30 3NJLyJcVfr4Uf9hJj3GUEUowJqq+uMqeyylA3446QecO2KiQUFwu2BS/qg4krM0Mp/ Az+gag7w+mnmgcKRtEVlBMnKmXLTtHXFNPjQwVRyS/fTbSPyxkeBANsVMeK+qIg7E+ EpzbpLVMWvBfgzuCa7xuJP7m9rLWL64BV23x6otmKaiOQR/GKVcMdSbARTPrkSgVQM cToT+fA3Vdk9StKkpHQtmCEf48byETIvCx92k8Sdi0+h3xxicAi55FVKX+l78kHVuw cAwbp8TSbOszg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 11C2B4F847; Thu, 3 Dec 2026 08:32:43 +0000 (UTC) From: florian.leferenz@wabtec.com Date: Thu, 03 Dec 2026 09:32:39 +0100 Subject: [PATCH wic] oe/path: don't follow symlinks in copyhardlinktree()'s hardlink test MIME-Version: 1.0 Message-Id: <20261203-fix-copyhardlinktree-dangling-symlink-v1-1-17e089e290a3@wabtec.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yWNyw6CQAxFf4V0bRNmRDT+imEB0wr1MZAOKoTw7 xZdnpP7WCCxCic4ZwsovyVJHw3cLoPQ1bFlFDIGn/vS+XyPV5kw9MPc1UoPifdRmZEsadBimp+ bxJM7HEsico0vwLYGZSv+fi7wkQDVX6ZXc+Mwbg+wrl9C7QPOjgAAAA== X-Change-ID: 20261203-fix-copyhardlinktree-dangling-symlink-81576ddd1b24 To: yocto-patches@lists.yoctoproject.org Cc: twoerner@gmail.com, Florian Leferenz X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796286762; l=3670; i=florian.leferenz@wabtec.com; s=20261203; h=from:subject:message-id; bh=TUTqd2afitAwV3XPgP9MsFd7y9Ko0nNWmPAoW0iPpKw=; b=RwH2iYjrXB4FpPDJDK6bNv3qYaRg6vKTs9qj3dwHwm+mOzB6KXby5fTRQxy5YJ4H7yl96Fyj8 3DUvHPQXXLKD1BPWVxjqxzF0Jar4pOtblR+OOrPqk0ezpslbliOyxtR 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 09:47:59 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/5654 From: Florian Leferenz copyhardlinktree() decides between hardlinking and a full tar copy by hardlinking the first file os.walk() returns. os.link() follows symlinks by default, so when that entry is a symlink whose target does not exist on the build host (e.g. var/lock -> /run/lock in a target rootfs) the test fails with ENOENT and the whole tree is copied with tar instead. Which entry comes first depends on the directory order of the host filesystem, so the same rootfs is hardlinked on one build host and fully copied on another. Link the entry itself instead of its target and add a regression test. Signed-off-by: Florian Leferenz --- wic: fix copyhardlinktree() hardlink test with dangling symlinks --- src/wic/oe/path.py | 2 +- tests/unit/test_oe_path.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) --- base-commit: 610a61a25e5fad0b62abd19d60f0b0e210b1df34 change-id: 20261203-fix-copyhardlinktree-dangling-symlink-81576ddd1b24 Best regards, diff --git a/src/wic/oe/path.py b/src/wic/oe/path.py index 95bb964..6d61a6c 100644 --- a/src/wic/oe/path.py +++ b/src/wic/oe/path.py @@ -112,7 +112,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/tests/unit/test_oe_path.py b/tests/unit/test_oe_path.py index 3abe1f0..181128b 100644 --- a/tests/unit/test_oe_path.py +++ b/tests/unit/test_oe_path.py @@ -1,8 +1,9 @@ """ Unit tests for wic/oe/path.py, covering wic's own path logic: join, is_path_parent, symlink, make_relative_symlink, canonicalize, which_wild, -and realpath. Thin standard-library wrappers (relative -> os.path.relpath, -find -> os.walk) are left to the standard library. +realpath and copyhardlinktree. Thin standard-library wrappers +(relative -> os.path.relpath, find -> os.walk) are left to the standard +library. """ import errno import os @@ -23,6 +24,7 @@ from wic.oe.path import ( canonicalize, which_wild, realpath, + copyhardlinktree, ) @@ -376,3 +378,26 @@ class TestRealpath: monkeypatch.setattr(os.path, "isdir", boom) assert realpath(str(sub), str(tmp_path), use_physdir=False) == str(sub) + + +class TestCopyhardlinktree: + def test_hardlinks_files(self, tmp_path): + src = tmp_path / "src" + (src / "sub").mkdir(parents=True) + (src / "sub" / "file").write_text("data") + dst = tmp_path / "dst" + copyhardlinktree(str(src), str(dst)) + assert os.path.samefile(src / "sub" / "file", dst / "sub" / "file") + + def test_dangling_symlink_as_first_entry_still_hardlinks(self, tmp_path): + # The hardlink test uses the first file os.walk() returns. A rootfs + # symlink such as var/lock -> /run/lock dangles on the build host and + # must not make the test fail and force a full tar copy. + src = tmp_path / "src" + (src / "sub").mkdir(parents=True) + os.symlink("/nonexistent/target", str(src / "dangling")) + (src / "sub" / "file").write_text("data") + dst = tmp_path / "dst" + copyhardlinktree(str(src), str(dst)) + assert os.path.samefile(src / "sub" / "file", dst / "sub" / "file") + assert os.readlink(dst / "dangling") == "/nonexistent/target"