From 717eae8dff0afbc380e4e9783ceee209d3926051 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Mon, 22 Nov 2021 14:03:26 -0600 Subject: [PATCH] bloom.do_bloom: always close filter; fix None vs 0 tests 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 Tested-by: Rob Browning --- lib/bup/cmd/bloom.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/bup/cmd/bloom.py b/lib/bup/cmd/bloom.py index 9963c43..667c5cc 100755 --- a/lib/bup/cmd/bloom.py +++ b/lib/bup/cmd/bloom.py @@ -77,7 +77,7 @@ def do_bloom(path, outfilename, k, force): 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: @@ -88,7 +88,7 @@ def do_bloom(path, outfilename, k, force): debug1("bloom: nothing to do.\n") return - if b: + if b is not None: if len(b) != rest_count: debug1("bloom: size %d != idx total %d, regenerating\n" % (len(b), rest_count)) @@ -107,9 +107,11 @@ def do_bloom(path, outfilename, k, force): 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) - 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 @@ -140,7 +142,7 @@ def do_bloom(path, outfilename, k, force): 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: b.close() + if b is not None: b.close() if tfname: os.rename(tfname, outfilename) -- 2.39.2