public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Henning Schild <henning.schild@siemens.com>
To: isar-users@googlegroups.com
Cc: Henning Schild <henning.schild@siemens.com>,
	Richard Purdie <richard.purdie@linuxfoundation.org>
Subject: [PATCH 2/3] lib/oe/path: try hardlinking instead of guessing when it might fail
Date: Mon,  6 Apr 2020 22:16:47 +0200	[thread overview]
Message-ID: <20200406201648.26945-3-henning.schild@siemens.com> (raw)
In-Reply-To: <20200406201648.26945-1-henning.schild@siemens.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>
---
 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 c6bb6042a3..3506e2c989 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.24.1


  parent reply	other threads:[~2020-04-06 20:16 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-06 20:16 [PATCH 0/3] fix and test wic exclude-path Henning Schild
2020-04-06 20:16 ` [PATCH 1/3] oe.path: Add copyhardlink() helper function Henning Schild
2020-04-06 20:16 ` Henning Schild [this message]
2020-04-06 20:16 ` [PATCH 3/3] CI: test the exclude-path feature of wic Henning Schild
2020-05-07 19:25   ` Baurzhan Ismagulov
2020-05-07 20:13     ` Henning Schild
2020-09-01 19:54   ` [PATCH v2 " Baurzhan Ismagulov
2020-09-02  5:30     ` vijaikumar....@gmail.com
2020-09-02 10:10       ` Henning Schild
2020-04-06 20:18 ` [PATCH 0/3] fix and test wic exclude-path Henning Schild
2020-06-10 15:26 ` Henning Schild
2020-06-12  6:55   ` Baurzhan Ismagulov
2020-06-12 15:17     ` Jan Kiszka
2020-06-12 18:11       ` Henning Schild
2020-06-12 18:17         ` Henning Schild
2020-06-12 18:44           ` Jan Kiszka
2020-06-12 18:22       ` Henning Schild
2020-06-12 18:46         ` Jan Kiszka
2020-06-12 18:03     ` Henning Schild
2020-09-01 19:53       ` Baurzhan Ismagulov
2020-09-02  5:24         ` vijaikumar....@gmail.com
2020-09-02 10:04         ` Henning Schild
2020-09-14 13:36 ` Baurzhan Ismagulov

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=20200406201648.26945-3-henning.schild@siemens.com \
    --to=henning.schild@siemens.com \
    --cc=isar-users@googlegroups.com \
    --cc=richard.purdie@linuxfoundation.org \
    /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