diff --git a/swh/storage/db.py b/swh/storage/db.py --- a/swh/storage/db.py +++ b/swh/storage/db.py @@ -14,6 +14,7 @@ """Proxy to the SWH DB, with wrappers around stored procedures """ + def mktemp_dir_entry(self, entry_type, cur=None): self._cursor(cur).execute('SELECT swh_mktemp_dir_entry(%s)', (('directory_entry_%s' % entry_type),)) @@ -206,11 +207,12 @@ cur.execute("""SELECT %s FROM swh_content_find(%%s, %%s, %%s, %%s) - LIMIT 1""" % ','.join(self.content_find_cols), + LIMIT ALL""" % ','.join(self.content_find_cols), (sha1, sha1_git, sha256, blake2s256)) - content = cur.fetchone() - if set(content) == {None}: + content = cur.fetchall() + print(content) + if set(content[0]) == {None}: return None else: return content diff --git a/swh/storage/in_memory.py b/swh/storage/in_memory.py --- a/swh/storage/in_memory.py +++ b/swh/storage/in_memory.py @@ -215,7 +215,7 @@ keys = list(set.intersection(*found)) # FIXME: should really be a list of all the objects found - return copy.deepcopy(self._contents[keys[0]]) + return copy.deepcopy([self._contents[key] for key in keys]) def content_missing(self, contents, key_hash='sha1'): """List content missing from storage @@ -244,8 +244,9 @@ else: # content_find cannot return None here, because we checked # above that there is a content with matching hashes. - if self.content_find(content)['status'] == 'missing': - yield content[key_hash] + for result in self.content_find(content): + if result['status'] == 'missing': + yield content[key_hash] def content_missing_per_sha1(self, contents): """List content missing from storage based only on sha1. diff --git a/swh/storage/storage.py b/swh/storage/storage.py --- a/swh/storage/storage.py +++ b/swh/storage/storage.py @@ -410,7 +410,7 @@ blake2s256=content.get('blake2s256'), cur=cur) if c: - return dict(zip(db.content_find_cols, c)) + return [dict(zip(db.content_find_cols, one_c)) for one_c in c] return None def directory_add(self, directories): diff --git a/swh/storage/tests/test_storage.py b/swh/storage/tests/test_storage.py --- a/swh/storage/tests/test_storage.py +++ b/swh/storage/tests/test_storage.py @@ -1609,44 +1609,45 @@ self.storage.content_add([cont]) actually_present = self.storage.content_find({'sha1': cont['sha1']}) - - actually_present.pop('ctime') - self.assertEqual(actually_present, { - 'sha1': cont['sha1'], - 'sha256': cont['sha256'], - 'sha1_git': cont['sha1_git'], - 'blake2s256': cont['blake2s256'], - 'length': cont['length'], - 'status': 'visible' - }) + for present in actually_present: + present.pop('ctime') + + self.assertEqual(present, { + 'sha1': cont['sha1'], + 'sha256': cont['sha256'], + 'sha1_git': cont['sha1_git'], + 'blake2s256': cont['blake2s256'], + 'length': cont['length'], + 'status': 'visible' + }) # 2. with something to find actually_present = self.storage.content_find( {'sha1_git': cont['sha1_git']}) - - actually_present.pop('ctime') - self.assertEqual(actually_present, { - 'sha1': cont['sha1'], - 'sha256': cont['sha256'], - 'sha1_git': cont['sha1_git'], - 'blake2s256': cont['blake2s256'], - 'length': cont['length'], - 'status': 'visible' - }) + for present in actually_present: + present.pop('ctime') + self.assertEqual(present, { + 'sha1': cont['sha1'], + 'sha256': cont['sha256'], + 'sha1_git': cont['sha1_git'], + 'blake2s256': cont['blake2s256'], + 'length': cont['length'], + 'status': 'visible' + }) # 3. with something to find actually_present = self.storage.content_find( {'sha256': cont['sha256']}) - - actually_present.pop('ctime') - self.assertEqual(actually_present, { - 'sha1': cont['sha1'], - 'sha256': cont['sha256'], - 'sha1_git': cont['sha1_git'], - 'blake2s256': cont['blake2s256'], - 'length': cont['length'], - 'status': 'visible' - }) + for present in actually_present: + present.pop('ctime') + self.assertEqual(present, { + 'sha1': cont['sha1'], + 'sha256': cont['sha256'], + 'sha1_git': cont['sha1_git'], + 'blake2s256': cont['blake2s256'], + 'length': cont['length'], + 'status': 'visible' + }) # 4. with something to find actually_present = self.storage.content_find({ @@ -1655,16 +1656,16 @@ 'sha256': cont['sha256'], 'blake2s256': cont['blake2s256'], }) - - actually_present.pop('ctime') - self.assertEqual(actually_present, { - 'sha1': cont['sha1'], - 'sha256': cont['sha256'], - 'sha1_git': cont['sha1_git'], - 'blake2s256': cont['blake2s256'], - 'length': cont['length'], - 'status': 'visible' - }) + for present in actually_present: + present.pop('ctime') + self.assertEqual(present, { + 'sha1': cont['sha1'], + 'sha256': cont['sha256'], + 'sha1_git': cont['sha1_git'], + 'blake2s256': cont['blake2s256'], + 'length': cont['length'], + 'status': 'visible' + }) def test_content_find_with_non_present_content(self): # 1. with something that does not exist