diff --git a/bin/autojump b/bin/autojump index 5dfa7ca..586bb20 100755 --- a/bin/autojump +++ b/bin/autojump @@ -23,6 +23,7 @@ from __future__ import division, print_function import collections import difflib +import errno import math import operator import os @@ -31,6 +32,7 @@ import shutil import sys import tempfile + try: import argparse except ImportError: @@ -39,6 +41,15 @@ except ImportError: import autojump_argparse as argparse sys.path.pop() + +def create_dir_atomically(path): + try: + os.makedirs(path) + except OSError as exception: + if exception.errno != errno.EEXIST: + raise + + class Database: """ Abstraction for interfacing with with autojump database file. @@ -96,7 +107,11 @@ class Database: if ((not os.path.exists(self.filename)) or os.name == 'nt' or os.getuid() == os.stat(self.filename)[4]): - temp = tempfile.NamedTemporaryFile(dir=self.config['data'], + + create_dir_atomically(self.config['data']) + + temp = tempfile.NamedTemporaryFile( + dir=self.config['data'], delete=False) for path, weight in sorted(self.data.items(), @@ -196,7 +211,7 @@ class Database: def set_defaults(): config = {} - config['version'] = 'release-v21.7.0' + config['version'] = 'release-v21.7.1' config['max_paths'] = 1000 config['separator'] = '__' config['home'] = os.path.expanduser('~')