]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
Add a bloom --ruin for testing failure cases
authorBrandon Low <lostlogic@lostlogicx.com>
Thu, 17 Feb 2011 06:41:33 +0000 (22:41 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Thu, 17 Feb 2011 09:09:54 +0000 (01:09 -0800)
This command option ruins a bloom filter by setting all of its bits to
zero.

Signed-off-by: Brandon Low <lostlogic@lostlogicx.com>
Documentation/bup-bloom.md
cmd/bloom-cmd.py

index 3d57c74ad0a7be81f09a91268a4da8ce545db59c..ef7c3a3436401ad20eb63c5bff2007c38c8fb7b7 100644 (file)
@@ -8,7 +8,7 @@ bup-bloom - generates, regenerates, updates bloom filters
 
 # SYNOPSIS
 
-bup bloom [-d dir] [-o outfile] [-k hashes] [-c idxfile]
+bup bloom [-d dir] [-o outfile] [-k hashes] [-c idxfile] [-f] [--ruin]
 
 # DESCRIPTION
 
@@ -18,6 +18,12 @@ updates or regenerates it as needed.
 
 # OPTIONS
 
+--ruin
+:   destroy bloom filters by setting the whole bitmask to
+    zeros.  you really want to know what you are doing if
+    run this and you want to delete the resulting bloom
+    when you are done with it.
+
 -f, --force
 :   don't update the existing bloom file; generate a new
     one from scratch.
index 47b4294ba7eec5fac62110b7a54a766c32886f9b..8639307517afbbfc5150021cd0f8998194d858e1 100755 (executable)
@@ -6,6 +6,7 @@ from bup.helpers import *
 optspec = """
 bup bloom [options...]
 --
+ruin       ruin the specified bloom file (clearing the bitfield)
 f,force    ignore existing bloom file and regenerate it from scratch
 o,output=  output bloom filename (default: auto)
 d,dir=     input directory to look for idx files (default: auto)
@@ -13,6 +14,17 @@ k,hashes=  number of hash functions to use (4 or 5) (default: auto)
 c,check=   check the given .idx file against the bloom filter
 """
 
+
+def ruin_bloom(bloomfilename):
+    rbloomfilename = git.repo_rel(bloomfilename)
+    if not os.path.exists(bloomfilename):
+        log("%s\n" % bloomfilename)
+        add_error("bloom: %s not found to ruin\n" % rbloomfilename)
+        return
+    b = bloom.ShaBloom(bloomfilename, readwrite=True, expected=1)
+    b.map[16:16+2**b.bits] = '\0' * 2**b.bits
+
+
 def check_bloom(path, bloomfilename, idx):
     rbloomfilename = git.repo_rel(bloomfilename)
     ridx = git.repo_rel(idx)
@@ -132,6 +144,8 @@ for path in paths:
     outfilename = opt.output or os.path.join(path, 'bup.bloom')
     if opt.check:
         check_bloom(path, outfilename, opt.check)
+    elif opt.ruin:
+        ruin_bloom(outfilename)
     else:
         do_bloom(path, outfilename)