summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/path.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-03 15:11:33 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-03 16:19:19 +0100
commit61823f61948df24c3329de2766c715e562711a94 (patch)
tree7d1bb6e610001f5eaff91b115d1cb670ff1de6f1 /meta/lib/oe/path.py
parentc09866b4cf9f43aadd997dd33016979b07d1c130 (diff)
downloadpoky-61823f61948df24c3329de2766c715e562711a94.tar.gz
path.py: Deal with race issue
The change to use copyhardlinktree in some of the sstate code instead of copytree exposed a race condition. This is due to cp failing if it finds a directory doesn't exist yet some other process creates it while cp was trying to create it itself. tar doesn't error in this case. To fix this we need to create the directory structure with tar, then use cp to hardlink the files. Messy but probably worth doing. I also took the opportunity to remove src_bak since the code is neater without it. (From OE-Core rev: 2f954a9a6932f1e6c564e7e7aacaac628a75eed7) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe/path.py')
-rw-r--r--meta/lib/oe/path.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py
index 4f8b66c2f3..76a6ed8314 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -87,16 +87,20 @@ def copytree(src, dst):
87def copyhardlinktree(src, dst): 87def copyhardlinktree(src, dst):
88 """ Make the hard link when possible, otherwise copy. """ 88 """ Make the hard link when possible, otherwise copy. """
89 bb.utils.mkdirhier(dst) 89 bb.utils.mkdirhier(dst)
90 src_bak = src 90 if os.path.isdir(src) and not len(os.listdir(src)):
91 if os.path.isdir(src): 91 return
92 if not len(os.listdir(src)): 92
93 return 93 if (os.stat(src).st_dev == os.stat(dst).st_dev):
94 src = src + "/*" 94 # Need to copy directories only with tar first since cp will error if two
95 if (os.stat(src_bak).st_dev == os.stat(dst).st_dev): 95 # writers try and create a directory at the same time
96 cmd = 'cd %s; find . -type d -print | tar -cf - -C %s -ps --files-from - | tar -xf - -C %s' % (src, src, dst)
97 check_output(cmd, shell=True, stderr=subprocess.STDOUT)
98 if os.path.isdir(src):
99 src = src + "/*"
96 cmd = 'cp -afl %s %s' % (src, dst) 100 cmd = 'cp -afl %s %s' % (src, dst)
97 check_output(cmd, shell=True, stderr=subprocess.STDOUT) 101 check_output(cmd, shell=True, stderr=subprocess.STDOUT)
98 else: 102 else:
99 copytree(src_bak, dst) 103 copytree(src, dst)
100 104
101def remove(path, recurse=True): 105def remove(path, recurse=True):
102 """Equivalent to rm -f or rm -rf""" 106 """Equivalent to rm -f or rm -rf"""