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(
handle_dir = ZODB.blob.remove_committed_dir
# Fist step: move or remove oids or revisions
fp = open(os.path.join(self.blob_dir, '.removed'), 'rb')
for line in fp:
line = binascii.unhexlify(line.strip())
with open(os.path.join(self.blob_dir, '.removed'), 'rb') as fp:
for line in fp:
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 is garbage, re/move dir
path = fshelper.getPathForOID(line)
oid, tid = line[:8], line[8:]
path = fshelper.getBlobFilename(oid, tid)
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:
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()
handle_file(path)
assert not os.path.exists(path)
maybe_remove_empty_dir_containing(path)
os.remove(os.path.join(self.blob_dir, '.removed'))
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