From 426d1c7ddaed844fab973a6d6f4a4ca79f4d7a81 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 15 Sep 2024 01:47:25 +0200 Subject: [PATCH] manifest: reorder methods, no other changes --- src/borg/manifest.py | 82 ++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/borg/manifest.py b/src/borg/manifest.py index 7fa6d97d4..a7f32323b 100644 --- a/src/borg/manifest.py +++ b/src/borg/manifest.py @@ -101,30 +101,19 @@ def finish(self, manifest): manifest_archives = StableDict(self._get_raw_dict()) return manifest_archives - def count(self): - # return the count of archives in the repo - return len(list(self.ids())) - - def exists(self, name): - # check if an archive with this name exists - assert isinstance(name, str) + def ids(self): + # yield the binary IDs of all archives if not self.legacy: - return name in self.names() + try: + infos = list(self.repository.store_list("archives")) + except ObjectNotFound: + infos = [] + for info in infos: + info = ItemInfo(*info) # RPC does not give us a NamedTuple + yield hex_to_bin(info.name) else: - return name in self._archives - - def exists_name_and_id(self, name, id): - # check if an archive with this name AND id exists - assert isinstance(name, str) - assert isinstance(id, bytes) - if not self.legacy: - for archive_info in self._infos(): - if archive_info["name"] == name and archive_info["id"] == id: - return True - else: - return False - else: - raise NotImplementedError + for archive_info in self._archives.values(): + yield archive_info["id"] def _get_archive_meta(self, id: bytes) -> dict: # get all metadata directly from the ArchiveItem in the repo. @@ -163,20 +152,6 @@ def _get_archive_meta(self, id: bytes) -> dict: ) return metadata - def ids(self): - # yield the binary IDs of all archives - if not self.legacy: - try: - infos = list(self.repository.store_list("archives")) - except ObjectNotFound: - infos = [] - for info in infos: - info = ItemInfo(*info) # RPC does not give us a NamedTuple - yield hex_to_bin(info.name) - else: - for archive_info in self._archives.values(): - yield archive_info["id"] - def _infos(self): # yield the infos of all archives for id in self.ids(): @@ -186,6 +161,36 @@ def _info_tuples(self): for info in self._infos(): yield ArchiveInfo(name=info["name"], id=info["id"], ts=parse_timestamp(info["time"])) + def count(self): + # return the count of archives in the repo + return len(list(self.ids())) + + def names(self): + # yield the names of all archives + for archive_info in self._infos(): + yield archive_info["name"] + + def exists(self, name): + # check if an archive with this name exists + assert isinstance(name, str) + if not self.legacy: + return name in self.names() + else: + return name in self._archives + + def exists_name_and_id(self, name, id): + # check if an archive with this name AND id exists + assert isinstance(name, str) + assert isinstance(id, bytes) + if not self.legacy: + for archive_info in self._infos(): + if archive_info["name"] == name and archive_info["id"] == id: + return True + else: + return False + else: + raise NotImplementedError + def _lookup_name(self, name, raw=False): assert isinstance(name, str) assert not self.legacy @@ -199,11 +204,6 @@ def _lookup_name(self, name, raw=False): else: raise KeyError(name) - def names(self): - # yield the names of all archives - for archive_info in self._infos(): - yield archive_info["name"] - def get(self, name, raw=False): assert isinstance(name, str) if not self.legacy: