mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
Creates data directory before attempting to save the database.
Fixes #218.
This commit is contained in:
parent
986f02124e
commit
0b25bef134
19
bin/autojump
19
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('~')
|
||||
|
Loading…
Reference in New Issue
Block a user