summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Schild <henning.schild@siemens.com>2020-01-24 14:48:47 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-02-04 15:56:29 +0000
commitd02d938cc635de77745d6f287f4222b148b9827d (patch)
tree5c6f1be39c70911ac4ab364f6728a7395df62e3a
parent0a99a2e2da76bff9edec3193af11f35506b2a88c (diff)
downloadpoky-d02d938cc635de77745d6f287f4222b148b9827d.tar.gz
lib/oe/path: try hardlinking instead of guessing when it might fail
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. (From OE-Core rev: f5571bda8327f927feb23b167ab4594b7d0c95bc) Signed-off-by: Henning Schild <henning.schild@siemens.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oe/path.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py
index fa209b9795..082972457b 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -99,7 +99,22 @@ def copyhardlinktree(src, dst):
99 if os.path.isdir(src) and not len(os.listdir(src)): 99 if os.path.isdir(src) and not len(os.listdir(src)):
100 return 100 return
101 101
102 if (os.stat(src).st_dev == os.stat(dst).st_dev): 102 canhard = False
103 testfile = None
104 for root, dirs, files in os.walk(src):
105 if len(files):
106 testfile = os.path.join(root, files[0])
107 break
108
109 if testfile is not None:
110 try:
111 os.link(testfile, os.path.join(dst, 'testfile'))
112 os.unlink(os.path.join(dst, 'testfile'))
113 canhard = True
114 except Exception as e:
115 bb.debug(2, "Hardlink test failed with " + str(e))
116
117 if (canhard):
103 # Need to copy directories only with tar first since cp will error if two 118 # Need to copy directories only with tar first since cp will error if two
104 # writers try and create a directory at the same time 119 # writers try and create a directory at the same time
105 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) 120 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):
121def copyhardlink(src, dst): 136def copyhardlink(src, dst):
122 """Make a hard link when possible, otherwise copy.""" 137 """Make a hard link when possible, otherwise copy."""
123 138
124 # We need to stat the destination directory as the destination file probably 139 try:
125 # doesn't exist yet.
126 dstdir = os.path.dirname(dst)
127 if os.stat(src).st_dev == os.stat(dstdir).st_dev:
128 os.link(src, dst) 140 os.link(src, dst)
129 else: 141 except OSError:
130 shutil.copy(src, dst) 142 shutil.copy(src, dst)
131 143
132def remove(path, recurse=True): 144def remove(path, recurse=True):