# HG changeset patch # User Doug Simon # Date 1362754537 -3600 # Node ID 0934903d28f35da96c90b7c7b2fd278c0dd88c9a # Parent 80a825206cbc2b56eee2846a01eff70955289cec use shutil.move to make concurrent updating/replacement of graal.jar atomic diff -r 80a825206cbc -r 0934903d28f3 mx/commands.py --- a/mx/commands.py Fri Mar 08 14:33:33 2013 +0100 +++ b/mx/commands.py Fri Mar 08 15:55:37 2013 +0100 @@ -385,7 +385,10 @@ for e in os.listdir(jdks): jreLibDir = join(jdks, e, 'jre', 'lib') if exists(jreLibDir): - shutil.copyfile(graalJar, join(jreLibDir, 'graal.jar')) + # do a copy and then a move to get atomic updating (on Unix) of graal.jar in the JRE + _, tmp = tempfile.mkstemp(suffix='', prefix='graal.jar', dir=jreLibDir) + shutil.copyfile(graalJar, tmp) + shutil.move(tmp, join(jreLibDir, 'graal.jar')) # run a command in the windows SDK Debug Shell def _runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo={}): diff -r 80a825206cbc -r 0934903d28f3 mxtool/mx.py --- a/mxtool/mx.py Fri Mar 08 14:33:33 2013 +0100 +++ b/mxtool/mx.py Fri Mar 08 15:55:37 2013 +0100 @@ -1651,7 +1651,8 @@ if name.startswith('@'): dname = name[1:] d = distribution(dname) - zf = zipfile.ZipFile(d.path, 'w') + _, tmp = tempfile.mkstemp(suffix='', prefix=basename(d.path), dir=dirname(d.path)) + zf = zipfile.ZipFile(tmp, 'w') for p in sorted_deps(d.deps): outputDir = p.output_dir() for root, _, files in os.walk(outputDir): @@ -1660,19 +1661,24 @@ arcname = join(relpath, f).replace(os.sep, '/') zf.write(join(root, f), arcname) zf.close() + # Atomic on Unix + shutil.move(tmp, d.path) + #print time.time(), 'move:', tmp, '->', d.path d.notify_updated() else: p = project(name) outputDir = p.output_dir() - jar = join(p.dir, p.name + '.jar') - zf = zipfile.ZipFile(jar, 'w') + _, tmp = tempfile.mkstemp(suffix='', prefix=p.name, dir=p.dir) + zf = zipfile.ZipFile(tmp, 'w') for root, _, files in os.walk(outputDir): for f in files: relpath = root[len(outputDir) + 1:] arcname = join(relpath, f).replace(os.sep, '/') zf.write(join(root, f), arcname) zf.close() + # Atomic on Unix + shutil.move(tmp, join(p.dir, p.name + '.jar')) def canonicalizeprojects(args): """process all project files to canonicalize the dependencies