summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Barker <paul@betafive.co.uk>2019-05-03 11:54:47 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-05-07 10:12:53 +0100
commit10a14af4ca1f93538ed03eaf0bf17078312280f4 (patch)
tree15e1561a5533c3611c759805dff9e9c583f64372
parent80bb16ee716386327bd3491b50282b2bd976edd7 (diff)
downloadpoky-10a14af4ca1f93538ed03eaf0bf17078312280f4.tar.gz
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. (From OE-Core rev: 5437efa16f9bec914e417c6c939a39c247084f52) 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>
-rw-r--r--meta/lib/oe/path.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py
index 1e24d0586b..c09eda5c42 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -90,7 +90,7 @@ def copytree(src, dst):
90 subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) 90 subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
91 91
92def copyhardlinktree(src, dst): 92def copyhardlinktree(src, dst):
93 """ Make the hard link when possible, otherwise copy. """ 93 """Make a tree of hard links when possible, otherwise copy."""
94 bb.utils.mkdirhier(dst) 94 bb.utils.mkdirhier(dst)
95 if os.path.isdir(src) and not len(os.listdir(src)): 95 if os.path.isdir(src) and not len(os.listdir(src)):
96 return 96 return
@@ -114,6 +114,17 @@ def copyhardlinktree(src, dst):
114 else: 114 else:
115 copytree(src, dst) 115 copytree(src, dst)
116 116
117def copyhardlink(src, dst):
118 """Make a hard link when possible, otherwise copy."""
119
120 # We need to stat the destination directory as the destination file probably
121 # doesn't exist yet.
122 dstdir = os.path.dirname(dst)
123 if os.stat(src).st_dev == os.stat(dstdir).st_dev:
124 os.link(src, dst)
125 else:
126 shutil.copy(src, dst)
127
117def remove(path, recurse=True): 128def remove(path, recurse=True):
118 """ 129 """
119 Equivalent to rm -f or rm -rf 130 Equivalent to rm -f or rm -rf