1
0
mirror of https://github.com/wting/autojump synced 2026-03-02 03:49:26 +00:00

Merge remote-tracking branch 'xiaonaitong/master' into windows

This commit is contained in:
Joël Schaerer
2011-09-27 15:42:55 +02:00
3 changed files with 24 additions and 17 deletions

View File

@@ -77,9 +77,9 @@ def unico(text):
def save(path_dict, dic_file):
"""Save the database in an atomic way, and preserve
a backup file."""
# If the dic_file exists, check that it belongs to us
# If the dic_file exists and os is not windows, check that it belongs to us
# Otherwise, fail quietly
if (not os.path.exists(dic_file)) or os.getuid() == os.stat(dic_file)[4]:
if (not os.path.exists(dic_file)) or os.name == 'nt' or os.getuid() == os.stat(dic_file)[4]:
temp = NamedTemporaryFile(dir=CONFIG_DIR, delete=False)
for path,weight in sorted(path_dict.items(),key=itemgetter(1),reverse=True):
# the db is stored in utf-8
@@ -88,7 +88,8 @@ def save(path_dict, dic_file):
os.fsync(temp)
temp.close()
#cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/
os.rename(temp.name, dic_file)
import shutil
shutil.move(temp.name, dic_file)
try: #backup file
import time
if (not os.path.exists(dic_file+".bak") or