Create tmpfile in the same dir as the cache file

Make sure we don't try to rename files across devices. Fixes bug 949366

Change-Id: I75581a0682c8db90cad9b077b1c22a886d234e31
This commit is contained in:
Florian Hines
2012-03-08 04:47:00 +00:00
parent ad6684a00f
commit f1290e8080

View File

@@ -1099,7 +1099,8 @@ def dump_recon_cache(cache_key, cache_value, cache_file, lock_timeout=2):
pass pass
cache_entry[cache_key] = cache_value cache_entry[cache_key] = cache_value
try: try:
with NamedTemporaryFile(delete=False) as tf: with NamedTemporaryFile(dir=os.path.dirname(cache_file),
delete=False) as tf:
tf.write(json.dumps(cache_entry) + '\n') tf.write(json.dumps(cache_entry) + '\n')
os.rename(tf.name, cache_file) os.rename(tf.name, cache_file)
finally: finally: