]> arthur.barton.de Git - bup.git/commitdiff
bloom.do_bloom: always close filter; fix None vs 0 tests
authorRob Browning <rlb@defaultvalue.org>
Mon, 22 Nov 2021 20:03:26 +0000 (14:03 -0600)
committerRob Browning <rlb@defaultvalue.org>
Wed, 24 Nov 2021 18:51:54 +0000 (12:51 -0600)
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>
lib/bup/cmd/bloom.py

index 9963c438e7aca690c123a4dccf82ec2034e1f7ad..667c5cc8dbe4b92c1024e11d12b872d1e86fa6df 100755 (executable)
@@ -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)