Browse Source

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/)

pull/18/head
Joël Schaerer 15 years ago
parent
commit
3bd45e5304
1 changed files with 8 additions and 3 deletions
  1. +8
    -3
      autojump

+ 8
- 3
autojump View File

@ -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…
Cancel
Save