generic-poky/scripts/gen-lockedsig-cache
Paul Eggleton 5febb1dc5b scripts/gen-lockedsig-cache: fix race with temp file creation
As part of populating the sstate-cache with an artifact (.tgz file) we
create a temp file and then atomically move it to the final name. Due to
the glob used in this script such temp files were being matched, and
between the time they were matched and the time the script started
copying files, the temp file may have vanished.

This fixes random "No such file or directory" failures building the
extensible SDK on build setups where the sstate-cache directory is shared
amongst multiple build machines.

(From OE-Core rev: 588de5198c641ea1cfc3e01a6d129296bd2f706b)

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2015-10-19 17:57:59 +01:00

51 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python
#
# gen-lockedsig-cache <locked-sigs.inc> <input-cachedir> <output-cachedir>
#
import os
import sys
import glob
import shutil
import errno
def mkdir(d):
try:
os.makedirs(d)
except OSError as e:
if e.errno != errno.EEXIST:
raise e
if len(sys.argv) < 3:
print("Incorrect number of arguments specified")
sys.exit(1)
sigs = []
with open(sys.argv[1]) as f:
for l in f.readlines():
if ":" in l:
sigs.append(l.split(":")[2].split()[0])
files = set()
for s in sigs:
p = sys.argv[2] + "/" + s[:2] + "/*" + s + "*"
files |= set(glob.glob(p))
p = sys.argv[2] + "/*/" + s[:2] + "/*" + s + "*"
files |= set(glob.glob(p))
for f in files:
_, ext = os.path.splitext(f)
if not ext in ['.tgz', '.siginfo', '.sig']:
# Most likely a temp file, skip it
continue
dst = f.replace(sys.argv[2], sys.argv[3])
destdir = os.path.dirname(dst)
mkdir(destdir)
if os.path.exists(dst):
os.remove(dst)
if (os.stat(f).st_dev == os.stat(destdir).st_dev):
os.link(f, dst)
else:
shutil.copyfile(f, dst)