Running a "split -n" for a larger file caused the assertion in
ShaBloom.__del__ to fail, i.e. the filter hadn't been explicitly
closed. Fix the logic in do_bloom to be careful about 0 vs None since
ShaBloom has a __len__ method, and add one missing explicit close().
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
progress('bloom: counting: %d\r' % i)
with git.open_idx(name) as ix:
ixbase = os.path.basename(name)
progress('bloom: counting: %d\r' % i)
with git.open_idx(name) as ix:
ixbase = os.path.basename(name)
- if b and (ixbase in b.idxnames):
+ if b is not None and (ixbase in b.idxnames):
rest.append(name)
rest_count += len(ix)
else:
rest.append(name)
rest_count += len(ix)
else:
debug1("bloom: nothing to do.\n")
return
debug1("bloom: nothing to do.\n")
return
if len(b) != rest_count:
debug1("bloom: size %d != idx total %d, regenerating\n"
% (len(b), rest_count))
if len(b) != rest_count:
debug1("bloom: size %d != idx total %d, regenerating\n"
% (len(b), rest_count))
b, b_tmp = None, b
b_tmp.close()
else:
b, b_tmp = None, b
b_tmp.close()
else:
+ b, b_tmp = None, b
+ b_tmp.close()
b = bloom.ShaBloom(outfilename, readwrite=True,
expected=add_count)
b = bloom.ShaBloom(outfilename, readwrite=True,
expected=add_count)
- if not b: # Need all idxs to build from scratch
+ if b is None: # Need all idxs to build from scratch
add += rest
add_count += rest_count
del rest
add += rest
add_count += rest_count
del rest
finally: # This won't handle pending exceptions correctly in py2
# Currently, there's an open file object for tfname inside b.
# Make sure it's closed before rename.
finally: # This won't handle pending exceptions correctly in py2
# Currently, there's an open file object for tfname inside b.
# Make sure it's closed before rename.
+ if b is not None: b.close()
if tfname:
os.rename(tfname, outfilename)
if tfname:
os.rename(tfname, outfilename)