From c889aa013ebb2c7e6b935c3f521e898616c03385 Mon Sep 17 00:00:00 2001 From: timotei Date: Sun, 17 Aug 2014 15:01:54 +0300 Subject: [PATCH] Close the temporary file before re-opening it. On Windows, we cannot reuse the temp.name to reopen the file *unless* it has been closed before [0]. This problem in turn made the `move_file` request to fail, since the file was still open at the time. [0] https://docs.python.org/2/library/tempfile.html#tempfile.NamedTemporaryFile --- bin/autojump_data.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/autojump_data.py b/bin/autojump_data.py index 3ce96c2..b3e9e5a 100644 --- a/bin/autojump_data.py +++ b/bin/autojump_data.py @@ -121,6 +121,8 @@ def save(config, data): try: # write to temp file temp = NamedTemporaryFile(delete=False) + # prevent Windows errors by closing the file before opening it. + temp.close() with open(temp.name, 'w', encoding='utf-8', errors='replace') as f: for path, weight in data.items():