Commit 6fb972a0 authored by Jeremy Hylton's avatar Jeremy Hylton

Use os.remove() in all cases, instead of mixing remove() and unlink().

Add one case where failure to remove is not a fatal error. And be more
specific about the error that is caught -- OSError only.
parent 1923ede9
...@@ -184,7 +184,7 @@ ...@@ -184,7 +184,7 @@
# may have a back pointer to a version record or to a non-version # may have a back pointer to a version record or to a non-version
# record. # record.
# #
__version__='$Revision: 1.62 $'[11:-2] __version__='$Revision: 1.63 $'[11:-2]
import struct, time, os, bpthread, string, base64, sys import struct, time, os, bpthread, string, base64, sys
from struct import pack, unpack from struct import pack, unpack
...@@ -288,7 +288,8 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -288,7 +288,8 @@ class FileStorage(BaseStorage.BaseStorage,
# Now open the file # Now open the file
if create: if create:
if os.path.exists(file_name): os.remove(file_name) if os.path.exists(file_name):
os.remove(file_name)
file=open(file_name,'w+b') file=open(file_name,'w+b')
file.write(packed_version) file.write(packed_version)
else: else:
...@@ -355,15 +356,20 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -355,15 +356,20 @@ class FileStorage(BaseStorage.BaseStorage,
f.flush() f.flush()
f.close() f.close()
try: try:
try: os.unlink(index_name) try:
except: pass os.remove(index_name)
except OSError:
pass
os.rename(tmp_name, index_name) os.rename(tmp_name, index_name)
except: pass except: pass
def _clear_index(self): def _clear_index(self):
index_name=self.__name__+'.index' index_name=self.__name__+'.index'
if os.path.exists(index_name): if os.path.exists(index_name):
os.unlink(index_name) try:
os.remove(index_name)
except OSError:
pass
def _sane(self, index, pos): def _sane(self, index, pos):
"""Sanity check saved index data by reading the last undone trans """Sanity check saved index data by reading the last undone trans
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment