mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
abort save if disk error writing temp file
This commit is contained in:
parent
d1712dd757
commit
a17abd3459
16
autojump
16
autojump
@ -85,10 +85,18 @@ def save(path_dict, dic_file):
|
|||||||
for path,weight in sorted(path_dict.items(),key=itemgetter(1),reverse=True):
|
for path,weight in sorted(path_dict.items(),key=itemgetter(1),reverse=True):
|
||||||
# the db is stored in utf-8
|
# the db is stored in utf-8
|
||||||
temp.write((unico("%s\t%s\n")%(weight,path)).encode("utf-8"))
|
temp.write((unico("%s\t%s\n")%(weight,path)).encode("utf-8"))
|
||||||
#cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/
|
|
||||||
temp.flush()
|
# Catching disk errors and skipping save since file handle can't be closed.
|
||||||
os.fsync(temp)
|
try:
|
||||||
temp.close()
|
#cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/
|
||||||
|
temp.flush()
|
||||||
|
os.fsync(temp)
|
||||||
|
temp.close()
|
||||||
|
except IOError as ex:
|
||||||
|
print("I/O error writing to temporary file. (%s)" %
|
||||||
|
ex, file=stderr)
|
||||||
|
return
|
||||||
|
|
||||||
# Use shutil.move instead of os.rename because windows doesn't support
|
# Use shutil.move instead of os.rename because windows doesn't support
|
||||||
# using rename to overwrite files
|
# using rename to overwrite files
|
||||||
shutil.move(temp.name, dic_file)
|
shutil.move(temp.name, dic_file)
|
||||||
|
Loading…
Reference in New Issue
Block a user