diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-11-20 20:30:40 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-11-20 20:30:40 +0200 |
commit | 6deaca063da5260477a4bcdac78fd18f44cd538d (patch) | |
tree | da9316c53055106167cd717814a94ea70c16fc31 | |
parent | 00d06aece5ab29ecc231805184dbe63a66004e4d (diff) | |
download | obnam-6deaca063da5260477a4bcdac78fd18f44cd538d.tar.gz |
Change find_chunk_ids_by_content to look up by token
Also rename the method
-rw-r--r-- | obnamlib/delegator.py | 4 | ||||
-rw-r--r-- | obnamlib/fmt_6/repo_fmt_6.py | 3 | ||||
-rw-r--r-- | obnamlib/fmt_ga/indexes.py | 3 | ||||
-rw-r--r-- | obnamlib/plugins/backup_plugin.py | 2 | ||||
-rw-r--r-- | obnamlib/repo_interface.py | 16 |
5 files changed, 14 insertions, 14 deletions
diff --git a/obnamlib/delegator.py b/obnamlib/delegator.py index b3cc2bcf..bd8b0a05 100644 --- a/obnamlib/delegator.py +++ b/obnamlib/delegator.py @@ -350,8 +350,8 @@ class RepositoryDelegator(obnamlib.RepositoryInterface): return self._chunk_indexes.put_chunk_into_indexes( chunk_id, token, client_id) - def find_chunk_ids_by_content(self, chunk_content): - return self._chunk_indexes.find_chunk_ids_by_content(chunk_content) + def find_chunk_ids_by_token(self, token): + return self._chunk_indexes.find_chunk_ids_by_token(token) def remove_chunk_from_indexes(self, chunk_id, client_id): self._require_we_got_chunk_indexes_lock() diff --git a/obnamlib/fmt_6/repo_fmt_6.py b/obnamlib/fmt_6/repo_fmt_6.py index 800f8b7e..4a67e399 100644 --- a/obnamlib/fmt_6/repo_fmt_6.py +++ b/obnamlib/fmt_6/repo_fmt_6.py @@ -812,8 +812,7 @@ class RepositoryFormat6(obnamlib.RepositoryInterface): self._chunksums.remove_for_all_clients(checksum, chunk_id) self._chunklist.remove(chunk_id) - def find_chunk_ids_by_content(self, data): - checksum = self._checksum(data) + def find_chunk_ids_by_token(self, checksum): candidates = self._chunksums.find(checksum) if candidates: return candidates diff --git a/obnamlib/fmt_ga/indexes.py b/obnamlib/fmt_ga/indexes.py index ef78b5b3..582fa77a 100644 --- a/obnamlib/fmt_ga/indexes.py +++ b/obnamlib/fmt_ga/indexes.py @@ -94,10 +94,9 @@ class GAChunkIndexes(object): client_ids.append(client_id) used_by[chunk_id] = client_ids - def find_chunk_ids_by_content(self, chunk_content): + def find_chunk_ids_by_token(self, token): self._load_data() - token = self.prepare_chunk_for_indexes(chunk_content) by_checksum = self._data['by_checksum']['sha512'] result = by_checksum.get(token, []) diff --git a/obnamlib/plugins/backup_plugin.py b/obnamlib/plugins/backup_plugin.py index d5783135..2f20154d 100644 --- a/obnamlib/plugins/backup_plugin.py +++ b/obnamlib/plugins/backup_plugin.py @@ -771,7 +771,7 @@ class BackupPlugin(obnamlib.ObnamPlugin): # exceptions, and other errors. We don't care: we'll just # pretend no chunk with the checksum exists yet. try: - in_tree = self.repo.find_chunk_ids_by_content(data) + in_tree = self.repo.find_chunk_ids_by_token(token) except larch.Error: in_tree = [] except obnamlib.RepositoryChunkContentNotInIndexes: diff --git a/obnamlib/repo_interface.py b/obnamlib/repo_interface.py index 906a31d1..c43cf25d 100644 --- a/obnamlib/repo_interface.py +++ b/obnamlib/repo_interface.py @@ -918,9 +918,11 @@ class RepositoryInterface(object): '''Removes a chunk from indexes, given its id, for all clients.''' raise NotImplementedError() - def find_chunk_ids_by_content(self, data): + def find_chunk_ids_by_token(self, token): '''Finds chunk ids that probably match a given content. + The token must be a return value of prepare_chunk_for_indexes. + This will raise RepositoryChunkContentNotInIndexes if the chunk is not in the indexes. Otherwise it will return all chunk ids that would have the same token (see @@ -2120,7 +2122,7 @@ class RepositoryInterfaceTests(unittest.TestCase): # pragma: no cover token = self.repo.prepare_chunk_for_indexes('foochunk') self.repo.put_chunk_into_indexes(chunk_id, token, 'fooclient') self.assertEqual( - self.repo.find_chunk_ids_by_content('foochunk'), [chunk_id]) + self.repo.find_chunk_ids_by_token(token), [chunk_id]) def test_finds_all_matching_chunk_ids(self): self.setup_client() @@ -2134,7 +2136,7 @@ class RepositoryInterfaceTests(unittest.TestCase): # pragma: no cover self.repo.put_chunk_into_indexes(chunk_id_2, token, 'fooclient') self.assertEqual( - set(self.repo.find_chunk_ids_by_content('foochunk')), + set(self.repo.find_chunk_ids_by_token(token)), set([chunk_id_1, chunk_id_2])) def test_removes_chunk_from_indexes(self): @@ -2146,7 +2148,7 @@ class RepositoryInterfaceTests(unittest.TestCase): # pragma: no cover self.repo.remove_chunk_from_indexes(chunk_id, 'fooclient') self.assertRaises( obnamlib.RepositoryChunkContentNotInIndexes, - self.repo.find_chunk_ids_by_content, 'foochunk') + self.repo.find_chunk_ids_by_token, token) def test_removes_chunk_from_indexes_for_all_clients(self): self.setup_two_clients() @@ -2158,7 +2160,7 @@ class RepositoryInterfaceTests(unittest.TestCase): # pragma: no cover self.repo.remove_chunk_from_indexes_for_all_clients(chunk_id) self.assertRaises( obnamlib.RepositoryChunkContentNotInIndexes, - self.repo.find_chunk_ids_by_content, 'foochunk') + self.repo.find_chunk_ids_by_token, token) def test_putting_chunk_to_indexes_without_locking_them_fails(self): chunk_id = self.repo.put_chunk_content('foochunk') @@ -2201,7 +2203,7 @@ class RepositoryInterfaceTests(unittest.TestCase): # pragma: no cover self.repo.unlock_chunk_indexes() self.assertRaises( obnamlib.RepositoryChunkContentNotInIndexes, - self.repo.find_chunk_ids_by_content, 'foochunk') + self.repo.find_chunk_ids_by_token, token) def test_committing_chunk_indexes_remembers_changes(self): self.setup_client() @@ -2212,7 +2214,7 @@ class RepositoryInterfaceTests(unittest.TestCase): # pragma: no cover self.repo.commit_chunk_indexes() self.repo.unlock_chunk_indexes() self.assertEqual( - self.repo.find_chunk_ids_by_content('foochunk'), [chunk_id]) + self.repo.find_chunk_ids_by_token(token), [chunk_id]) def test_committing_does_NOT_remove_chunk_indexes_lock(self): self.repo.lock_chunk_indexes() |