From 96d21a7b501e453376be19c426059e8c392a8173 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 17 Mar 2016 18:30:37 +0200 Subject: Store/use checksum algorithm in per-client data --- obnamlib/fmt_ga/client.py | 11 ++++++++++- obnamlib/fmt_ga/format.py | 9 +++++++-- 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 -- cgit v1.2.1