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: Paul Barker <paul@betafive.co.uk>,
	Ross Burton <ross.burton@intel.com>,
	Richard Purdie <richard.purdie@linuxfoundation.org>
Subject: [PATCH 1/3] oe.path: Add copyhardlink() helper function
Date: Mon,  6 Apr 2020 22:16:46 +0200	[thread overview]
Message-ID: <20200406201648.26945-2-henning.schild@siemens.com> (raw)
In-Reply-To: <20200406201648.26945-1-henning.schild@siemens.com>

From: Paul Barker <paul@betafive.co.uk>

This function creates hard links if possible, falling back to copying
the file if the destination is on a different volume to the source.

The docstring for copyhardlinktree() is also updated to make the
difference between the two functions a little clearer.

Signed-off-by: Paul Barker <paul@betafive.co.uk>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/lib/oe/path.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py
index 90c87f5239..c6bb6042a3 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -94,7 +94,7 @@ def copytree(src, dst):
     subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
 
 def copyhardlinktree(src, dst):
-    """ Make the hard link when possible, otherwise copy. """
+    """Make a tree of hard links when possible, otherwise copy."""
     bb.utils.mkdirhier(dst)
     if os.path.isdir(src) and not len(os.listdir(src)):
         return
@@ -118,6 +118,17 @@ def copyhardlinktree(src, dst):
     else:
         copytree(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:
+        os.link(src, dst)
+    else:
+        shutil.copy(src, dst)
+
 def remove(path, recurse=True):
     """
     Equivalent to rm -f or rm -rf
-- 
2.24.1


  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 ` Henning Schild [this message]
2020-04-06 20:16 ` [PATCH 2/3] lib/oe/path: try hardlinking instead of guessing when it might fail Henning Schild
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-2-henning.schild@siemens.com \
    --to=henning.schild@siemens.com \
    --cc=isar-users@googlegroups.com \
    --cc=paul@betafive.co.uk \
    --cc=richard.purdie@linuxfoundation.org \
    --cc=ross.burton@intel.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