From: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com>
To: <isar-users@googlegroups.com>, <Vijaikumar_Kanagarajan@mentor.com>
Subject: [RFC PATCH 05/10] lib/oe/path: try hardlinking instead of guessing when it might fail
Date: Mon, 24 Aug 2020 16:29:00 +0530 [thread overview]
Message-ID: <20200824105905.21110-1-Vijaikumar_Kanagarajan@mentor.com> (raw)
In-Reply-To: <20200824092750.19642-5-Vijaikumar_Kanagarajan@mentor.com>
From: Henning Schild <henning.schild@siemens.com>
The comparison of the stat st_dev is not enough to judge whether
hardlinking will work. One example would be where you try and hardlink
across two bind-mounts of a directory. The st_dev will be the same and
the operation will still fail.
Instead of implementing a check to try and figure out hardlink support
just try hardlinking and fall back to a copy when running into an
exception.
Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
[Vijai: Imported from OE core f5571bda8327f927feb23b167ab4594b7d0c95bc]
Signed-off-by: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com>
---
meta/lib/oe/path.py | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py
index c6bb604..3506e2c 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -99,7 +99,22 @@ def copyhardlinktree(src, dst):
if os.path.isdir(src) and not len(os.listdir(src)):
return
- if (os.stat(src).st_dev == os.stat(dst).st_dev):
+ canhard = False
+ testfile = None
+ for root, dirs, files in os.walk(src):
+ if len(files):
+ testfile = os.path.join(root, files[0])
+ break
+
+ if testfile is not None:
+ try:
+ os.link(testfile, os.path.join(dst, 'testfile'))
+ os.unlink(os.path.join(dst, 'testfile'))
+ canhard = True
+ except Exception as e:
+ bb.debug(2, "Hardlink test failed with " + str(e))
+
+ if (canhard):
# Need to copy directories only with tar first since cp will error if two
# writers try and create a directory at the same time
cmd = "cd %s; find . -type d -print | tar --xattrs --xattrs-include='*' -cf - -S -C %s -p --no-recursion --files-from - | tar --xattrs --xattrs-include='*' -xhf - -C %s" % (src, src, dst)
@@ -121,12 +136,9 @@ def copyhardlinktree(src, dst):
def copyhardlink(src, dst):
"""Make a hard link when possible, otherwise copy."""
- # We need to stat the destination directory as the destination file probably
- # doesn't exist yet.
- dstdir = os.path.dirname(dst)
- if os.stat(src).st_dev == os.stat(dstdir).st_dev:
+ try:
os.link(src, dst)
- else:
+ except OSError:
shutil.copy(src, dst)
def remove(path, recurse=True):
--
2.17.1
next prev parent reply other threads:[~2020-08-24 10:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-24 9:27 [RFC PATCH 00/10] WIC update Vijai Kumar K
2020-08-24 9:27 ` [RFC PATCH 01/10] wic: Update to the latest wic from openembedded core Vijai Kumar K
2020-08-24 9:27 ` [RFC PATCH 02/10] wic/plugins: Fix wic plugins to work with the latest wic Vijai Kumar K
2020-08-24 9:27 ` [RFC PATCH 03/10] wic-img: Satisfy the quirks of " Vijai Kumar K
2020-08-24 9:27 ` [RFC PATCH 04/10] oe.path: Add copyhardlink() helper function Vijai Kumar K
2020-08-24 10:59 ` Vijai Kumar K [this message]
2020-08-24 10:59 ` [RFC PATCH 06/10] wic_fakeroot: Handle standalone pseudo invocations Vijai Kumar K
2020-08-24 10:59 ` [RFC PATCH 07/10] meta-isar/conf: Add provision to debug WIC Vijai Kumar K
2020-08-24 10:59 ` [RFC PATCH 08/10] debian-common: Add tar as a dependency for wic Vijai Kumar K
2020-08-24 10:59 ` [RFC PATCH 09/10] scripts/lib/wic: Add /bin to the list of searchpaths Vijai Kumar K
2020-08-24 11:02 ` [RFC PATCH 10/10] meta-isar/canned-wks: Remove /boot mountpoint Vijai Kumar K
2020-08-31 14:03 ` [RFC PATCH 00/10] WIC update Jan Kiszka
2020-08-31 14:57 ` vijaikumar....@gmail.com
2020-09-01 16:53 ` vijaikumar....@gmail.com
2020-09-01 16:57 ` Jan Kiszka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200824105905.21110-1-Vijaikumar_Kanagarajan@mentor.com \
--to=vijaikumar_kanagarajan@mentor.com \
--cc=isar-users@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox