Commit 68d8bca1 authored by Marius Gedminas's avatar Marius Gedminas

Use with open(): ... for peace of mind

parent 033512a3
...@@ -1183,34 +1183,32 @@ class FileStorage( ...@@ -1183,34 +1183,32 @@ class FileStorage(
handle_dir = ZODB.blob.remove_committed_dir handle_dir = ZODB.blob.remove_committed_dir
# Fist step: move or remove oids or revisions # Fist step: move or remove oids or revisions
fp = open(os.path.join(self.blob_dir, '.removed'), 'rb') with open(os.path.join(self.blob_dir, '.removed'), 'rb') as fp:
for line in fp: for line in fp:
line = binascii.unhexlify(line.strip()) line = binascii.unhexlify(line.strip())
if len(line) == 8:
# oid is garbage, re/move dir
path = fshelper.getPathForOID(line)
if not os.path.exists(path):
# Hm, already gone. Odd.
continue
handle_dir(path)
maybe_remove_empty_dir_containing(path, 1)
continue
if len(line) != 16:
raise ValueError("Bad record in ", self.blob_dir, '.removed')
if len(line) == 8: oid, tid = line[:8], line[8:]
# oid is garbage, re/move dir path = fshelper.getBlobFilename(oid, tid)
path = fshelper.getPathForOID(line)
if not os.path.exists(path): if not os.path.exists(path):
# Hm, already gone. Odd. # Hm, already gone. Odd.
continue continue
handle_dir(path) handle_file(path)
maybe_remove_empty_dir_containing(path, 1) assert not os.path.exists(path)
continue maybe_remove_empty_dir_containing(path)
if len(line) != 16:
fp.close()
raise ValueError("Bad record in ", self.blob_dir, '.removed')
oid, tid = line[:8], line[8:]
path = fshelper.getBlobFilename(oid, tid)
if not os.path.exists(path):
# Hm, already gone. Odd.
continue
handle_file(path)
assert not os.path.exists(path)
maybe_remove_empty_dir_containing(path)
fp.close()
os.remove(os.path.join(self.blob_dir, '.removed')) os.remove(os.path.join(self.blob_dir, '.removed'))
if not self.pack_keep_old: if not self.pack_keep_old:
......
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