From f1290e8080e79ccb7ba8af9b749319fa548aec3c Mon Sep 17 00:00:00 2001 From: Florian Hines Date: Thu, 8 Mar 2012 04:47:00 +0000 Subject: [PATCH] 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 --- swift/common/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swift/common/utils.py b/swift/common/utils.py index ecf8558b6b..c7c752e33f 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -1099,7 +1099,8 @@ def dump_recon_cache(cache_key, cache_value, cache_file, lock_timeout=2): pass cache_entry[cache_key] = cache_value 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') os.rename(tf.name, cache_file) finally: