From 8fffbad95ac5626f4d9688276ba8a36808c433e3 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Fri, 13 Mar 2015 15:25:29 +0800 Subject: [PATCH] put temporary data file in the same director as the data file itself This should make shutil.move use rename, which is atomic, avoiding losing data when interweaving writes happen. This will close joelthelion/autojump#358. --- bin/autojump_data.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/autojump_data.py b/bin/autojump_data.py index 2ba7fbb..d647a42 100644 --- a/bin/autojump_data.py +++ b/bin/autojump_data.py @@ -120,11 +120,12 @@ def migrate_osx_xdg_data(config): def save(config, data): """Save data and create backup, creating a new data file if necessary.""" - create_dir(os.path.dirname(config['data_path'])) + data_dir = os.path.dirname(config['data_path']) + create_dir(data_dir) # atomically save by writing to temporary file and moving to destination try: - temp = NamedTemporaryFile(delete=False) + temp = NamedTemporaryFile(delete=False, dir=data_dir) # Windows cannot reuse the same open file name temp.close()