summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-12-24 23:33:05 +0000
committerLars Wirzenius <liw@liw.fi>2013-12-28 21:51:25 +0000
commitbae70f9b6085630f278555d20beb52d387bca651 (patch)
tree3fbb263cb763fc25593f2969bc75398e257e38a0
parentdcce3ed1a9c8f6fa35e36842d80d6cbd85382483 (diff)
downloadobnam-bae70f9b6085630f278555d20beb52d387bca651.tar.gz
Add RepositoryInterface.validate_chunk_content method
-rw-r--r--obnamlib/plugins/restore_plugin.py5
-rw-r--r--obnamlib/repo_dummy.py4
-rw-r--r--obnamlib/repo_fmt_6.py9
-rw-r--r--obnamlib/repo_interface.py40
-rw-r--r--test-gpghome/random_seedbin600 -> 600 bytes
5 files changed, 52 insertions, 6 deletions
diff --git a/obnamlib/plugins/restore_plugin.py b/obnamlib/plugins/restore_plugin.py
index bc8b42d3..bdbcfed5 100644
--- a/obnamlib/plugins/restore_plugin.py
+++ b/obnamlib/plugins/restore_plugin.py
@@ -302,10 +302,7 @@ class RestorePlugin(obnamlib.ObnamPlugin):
f.write('\0')
def verify_chunk_checksum(self, data, chunkid):
- # FIXME: The RepositoryInterface does not currently have
- # a way to do this, so at this time this is a no-op, to be
- # fixed later.
- pass
+ self.repo.validate_chunk_content(chunkid)
def restore_fifo(self, gen, filename, metadata):
logging.debug('restoring fifo %s' % filename)
diff --git a/obnamlib/repo_dummy.py b/obnamlib/repo_dummy.py
index 078bed6b..61800593 100644
--- a/obnamlib/repo_dummy.py
+++ b/obnamlib/repo_dummy.py
@@ -659,6 +659,8 @@ class RepositoryFormatDummy(obnamlib.RepositoryInterface):
def remove_chunk_from_indexes(self, chunk_id, client_id):
return self._chunk_indexes.remove_chunk(chunk_id, client_id)
+ def validate_chunk_content(self, chunk_id):
+ return None
+
def get_fsck_work_item(self):
return 'this pretends to be a work item'
-
diff --git a/obnamlib/repo_fmt_6.py b/obnamlib/repo_fmt_6.py
index 9288805b..920b5d04 100644
--- a/obnamlib/repo_fmt_6.py
+++ b/obnamlib/repo_fmt_6.py
@@ -685,6 +685,15 @@ class RepositoryFormat6(obnamlib.RepositoryInterface):
return chunk_id
raise obnamlib.RepositoryChunkContentNotInIndexes()
+ def validate_chunk_content(self, chunk_id):
+ try:
+ content = self.get_chunk_content(chunk_id)
+ except obnamlib.RepositoryChunkDoesNotExist:
+ return False
+ actual_checksum = self._checksum(content)
+ expected_checksum = self._chunklist.get_checksum(chunk_id)
+ return actual_checksum == expected_checksum
+
# Individual files in a generation.
def _setup_file_keys(self):
diff --git a/obnamlib/repo_interface.py b/obnamlib/repo_interface.py
index 38f33b61..6fc02034 100644
--- a/obnamlib/repo_interface.py
+++ b/obnamlib/repo_interface.py
@@ -709,6 +709,26 @@ class RepositoryInterface(object):
'''
raise NotImplementedError()
+ def validate_chunk_content(self, chunk_id):
+ '''Make sure the content of a chunk is valid.
+
+ This is (presumably) done by storing a checksum of the chunk
+ data in the chunk indexes, and then verifying that. However,
+ it could be done by error checking codes. It could also not be
+ done at all: if a repository format does not have chunk
+ indexes in any form, it can just return None for all
+ validation.
+
+ If a chunk is missing, it should be treated as an invalid
+ chunk (return False or None, depending).
+
+ Return True if content is valid, False if it is invalid, and
+ None if it is not known either way.
+
+ '''
+
+ raise NotImplementedError()
+
# Fsck.
def get_fsck_work_item(self):
@@ -1757,8 +1777,26 @@ class RepositoryInterfaceTests(unittest.TestCase): # pragma: no cover
self.repo.force_chunk_indexes_lock()
self.assertEqual(self.repo.lock_chunk_indexes(), None)
+ def test_validate_chunk_content_returns_True_or_None(self):
+ self.setup_client()
+ chunk_id = self.repo.put_chunk_content('foochunk')
+ self.repo.lock_chunk_indexes()
+ self.repo.put_chunk_into_indexes(chunk_id, 'foochunk', 'fooclient')
+ self.repo.commit_chunk_indexes()
+ ret = self.repo.validate_chunk_content(chunk_id)
+ self.assertTrue(ret is True or ret is None)
+
+ def test_validate_chunk_content_returns_False_or_None_if_corrupted(self):
+ self.setup_client()
+ chunk_id = self.repo.put_chunk_content('foochunk')
+ self.repo.lock_chunk_indexes()
+ self.repo.put_chunk_into_indexes(chunk_id, 'foochunk', 'fooclient')
+ self.repo.commit_chunk_indexes()
+ self.repo.remove_chunk(chunk_id)
+ ret = self.repo.validate_chunk_content(chunk_id)
+ self.assertTrue(ret is False or ret is None)
+
# Fsck.
def test_returns_fsck_work_item(self):
self.assertNotEqual(self.repo.get_fsck_work_item(), None)
-
diff --git a/test-gpghome/random_seed b/test-gpghome/random_seed
index 2a075662..3a3a9272 100644
--- a/test-gpghome/random_seed
+++ b/test-gpghome/random_seed
Binary files differ