Skip to content

Commit

Permalink
put temporary data file in the same director as the data file itself
Browse files Browse the repository at this point in the history
This should make shutil.move use rename, which is atomic, avoiding
losing data when interweaving writes happen.

This will close wting#358.
  • Loading branch information
lilydjwg authored and wting committed Sep 9, 2018
1 parent daa496b commit 8fffbad
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bin/autojump_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 8fffbad

Please sign in to comment.