reworking block skipper

This commit is contained in:
Edwin Eefting 2022-03-07 21:08:56 +01:00
parent b68ca19e5f
commit 233745c345
4 changed files with 54 additions and 7 deletions

View File

@ -98,3 +98,55 @@ class TestBlockHasher(unittest2.TestCase):
checksums = list(block_hasher.generate("tests/data/whole_whole2_partial"))
checksums.reverse()
self.assertEqual([], list(block_hasher.compare("tests/data/whole_whole2_partial", checksums)))
def test_skip1(self):
block_hasher = BlockHasher(count=1, skip=1)
self.assertEqual(
list(block_hasher.generate("tests/data/whole_whole2_partial")),
[
(0, "3c0bf91170d873b8e327d3bafb6bc074580d11b7"), # whole
# (1, "2e863f1fcccd6642e4e28453eba10d2d3f74d798"), # whole2
(2, "642027d63bb0afd7e0ba197f2c66ad03e3d70de1") # partial
]
)
#should continue the pattern on the next file:
self.assertEqual(
list(block_hasher.generate("tests/data/whole_whole2_partial")),
[
# (0, "3c0bf91170d873b8e327d3bafb6bc074580d11b7"), # whole
(1, "2e863f1fcccd6642e4e28453eba10d2d3f74d798"), # whole2
# (2, "642027d63bb0afd7e0ba197f2c66ad03e3d70de1") # partial
]
)
def test_skip6(self):
block_hasher = BlockHasher(count=1, skip=6)
self.assertEqual(
list(block_hasher.generate("tests/data/whole_whole2_partial")),
[
(0, "3c0bf91170d873b8e327d3bafb6bc074580d11b7"), # whole
# (1, "2e863f1fcccd6642e4e28453eba10d2d3f74d798"), # whole2
# (2, "642027d63bb0afd7e0ba197f2c66ad03e3d70de1") # partial
]
)
#all blocks of next file are skipped
self.assertEqual(
list(block_hasher.generate("tests/data/whole_whole2_partial")),
[
# (0, "3c0bf91170d873b8e327d3bafb6bc074580d11b7"), # whole
# (1, "2e863f1fcccd6642e4e28453eba10d2d3f74d798"), # whole2
# (2, "642027d63bb0afd7e0ba197f2c66ad03e3d70de1") # partial
]
)
#first block of this one is the 6th to be skipped:
self.assertEqual(
list(block_hasher.generate("tests/data/whole_whole2_partial")),
[
# (0, "3c0bf91170d873b8e327d3bafb6bc074580d11b7"), # whole
(1, "2e863f1fcccd6642e4e28453eba10d2d3f74d798"), # whole2
# (2, "642027d63bb0afd7e0ba197f2c66ad03e3d70de1") # partial
]
)

View File

@ -61,14 +61,9 @@ class BlockHasher():
yields nothing for empty files.
"""
with os.open(fname, os.O_RDONLY) as fh:
print (os.lseek(fh, 0, os.SEEK_END))
with os.openopen(fname, "rb") as fh:
# print(os.path.getsize(fname))
print(os.lseek(fh, 0, os.SEEK_END))
with open(fname, "rb") as fh:
fsize = fh.seek(0, os.SEEK_END)
fh.seek(0)

View File

@ -39,7 +39,7 @@ class ZfsCheck(CliBase):
group.add_argument('--check', '-c', metavar="FILE", default=None, const=True, nargs='?',
help="Read hashes from STDIN (or FILE) and compare them")
group.add_argument('--skip', '-s', metavar="NUMBER", default=0, type=float,
group.add_argument('--skip', '-s', metavar="NUMBER", default=0, type=int,
help="Skip this number of chunks after every hash. %(default)s")
return parser