1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00

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
This commit is contained in:
timotei 2014-08-17 15:01:54 +03:00
parent f23727ed0f
commit 538e499a3e

View File

@ -121,6 +121,8 @@ def save(config, data):
try: try:
# write to temp file # write to temp file
temp = NamedTemporaryFile(delete=False) 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: with open(temp.name, 'w', encoding='utf-8', errors='replace') as f:
for path, weight in data.items(): for path, weight in data.items():