summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2016-03-17 18:30:37 +0200
committerLars Wirzenius <liw@liw.fi>2016-03-17 20:54:11 +0200
commit96d21a7b501e453376be19c426059e8c392a8173 (patch)
tree401ec8bcc2d8e9b7cd81b3eab9b35ea8a6529dcb
parent45b3bd4949248e5fd0973ed3f04db86bbef5818e (diff)
downloadobnam-96d21a7b501e453376be19c426059e8c392a8173.tar.gz
Store/use checksum algorithm in per-client data
-rw-r--r--obnamlib/fmt_ga/client.py11
-rw-r--r--obnamlib/fmt_ga/format.py9
2 files changed, 17 insertions, 3 deletions
diff --git a/obnamlib/fmt_ga/client.py b/obnamlib/fmt_ga/client.py
index 8ea4b549..b204c720 100644
--- a/obnamlib/fmt_ga/client.py
+++ b/obnamlib/fmt_ga/client.py
@@ -32,6 +32,7 @@ class GAClient(object):
self._dirname = None
self._client_name = client_name
self._current_time = None
+ self._default_checksum_algorithm = None
self.clear()
def clear(self):
@@ -41,6 +42,7 @@ class GAClient(object):
self._data_is_loaded = False
self._dir_cache_size = obnamlib.DEFAULT_DIR_CACHE_BYTES
self._dir_bag_size = obnamlib.DEFAULT_DIR_BAG_BYTES
+ self._checksum_algorithm = None
def set_current_time(self, current_time):
self._current_time = current_time
@@ -48,6 +50,9 @@ class GAClient(object):
def set_fs(self, fs):
self._fs = fs
+ def set_default_checksum_algorithm(self, name):
+ self._default_checksum_algorithm = name
+
def set_dir_bag_size(self, size):
self._dir_bag_size = size
if self._blob_store:
@@ -99,6 +104,7 @@ class GAClient(object):
def _save_per_client_data(self):
data = {
+ 'whole-file-checksum': self._checksum_algorithm,
'keys': self._client_keys.as_dict(),
'generations': [g.as_dict() for g in self._generations],
}
@@ -116,8 +122,11 @@ class GAClient(object):
def _load_per_client_data(self):
blob_store = self._get_blob_store()
blob = blob_store.get_well_known_blob(self._well_known_blob)
- if blob is not None:
+ if blob is None:
+ self._checksum_algorithm = self._default_checksum_algorithm
+ else:
data = obnamlib.deserialise_object(blob)
+ self._checksum_algorithm = data['whole-file-checksum']
self._client_keys.set_from_dict(data['keys'])
for gen_dict in data['generations']:
gen = GAGeneration()
diff --git a/obnamlib/fmt_ga/format.py b/obnamlib/fmt_ga/format.py
index dfda1cc0..8e4b787b 100644
--- a/obnamlib/fmt_ga/format.py
+++ b/obnamlib/fmt_ga/format.py
@@ -27,10 +27,10 @@ class RepositoryFormatGA(obnamlib.RepositoryDelegator):
obnamlib.RepositoryDelegator.__init__(self, **kwargs)
self.set_client_list_object(obnamlib.GAClientList())
- self.set_client_factory(obnamlib.GAClient)
+ self.set_client_factory(self._client_factory)
self.set_chunk_indexes_object(obnamlib.GAChunkIndexes())
- assert 'checksum_algorithm' in kwargs
+ self._checksum_algorithm = kwargs['checksum_algorithm']
self._chunk_indexes.set_default_checksum_algorithm(
kwargs['checksum_algorithm'])
@@ -41,6 +41,11 @@ class RepositoryFormatGA(obnamlib.RepositoryDelegator):
chunk_store.set_chunk_cache_size(kwargs['chunk_cache_size'])
self.set_chunk_store_object(chunk_store)
+ def _client_factory(self, client_name):
+ client = obnamlib.GAClient(client_name)
+ client.set_default_checksum_algorithm(self._checksum_algorithm)
+ return client
+
def init_repo(self):
pass