mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
according to T'so, this is the correct way to do atomic writes in a file (http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/)
This commit is contained in:
parent
29046f4dce
commit
3bd45e5304
11
autojump
11
autojump
@ -32,9 +32,14 @@ def match(path,pattern,path_dict,re_flags=0):
|
||||
return False
|
||||
|
||||
def save(path_dict,dic_file):
|
||||
cPickle.dump(path_dict,open(dic_file+".tmp",'w'),-1)
|
||||
import shutil
|
||||
shutil.copy(dic_file+".tmp",dic_file) #cPickle.dump doesn't seem to be atomic, so this is more secure
|
||||
f=open(dic_file+".tmp",'w')
|
||||
cPickle.dump(path_dict,f,-1)
|
||||
f.flush()
|
||||
os.fsync(f)
|
||||
f.close()
|
||||
os.rename(dic_file+".tmp",dic_file) #cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/
|
||||
#import shutil
|
||||
#shutil.copy(dic_file+".tmp",dic_file) #cPickle.dump doesn't seem to be atomic, so this is more secure
|
||||
|
||||
def forget(path_dict,dic_file):
|
||||
"""Gradually forget about directories. Only call from the actual jump since it can take time"""
|
||||
|
Loading…
Reference in New Issue
Block a user