[oe-commits] [openembedded-core] 13/14: oe.path: Add copyhardlink() helper function

git at git.openembedded.org git at git.openembedded.org
Fri May 3 16:31:30 UTC 2019


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 68ebead3bc998e1b747077f1d10c7a2e86139cf6
Author: Paul Barker <paul at betafive.co.uk>
AuthorDate: Fri May 3 11:54:47 2019 +0000

    oe.path: Add copyhardlink() helper function
    
    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 at betafive.co.uk>
    Signed-off-by: Ross Burton <ross.burton at intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at 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 1e24d05..c09eda5 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -90,7 +90,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
@@ -114,6 +114,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

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list