From 3ca99d8839d165b7a53af2c7b0019be6f876f33d Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Tue, 14 Mar 2023 23:40:59 +0000 Subject: [PATCH] Require `Storage.search_metadata` to return files in lexicographical order to minimise dependencies between bundles --- codearchiver/storage.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/codearchiver/storage.py b/codearchiver/storage.py index 3d7aae5..118a786 100644 --- a/codearchiver/storage.py +++ b/codearchiver/storage.py @@ -29,7 +29,7 @@ class Storage(abc.ABC): ''' Search all metadata in storage by criteria. Refer to `codearchiver.core.Metadata.matches` for the semantics of `criteria`. - Yields all filenames where all criteria match. + Yields all filenames where all criteria match in lexicographical order. ''' @abc.abstractmethod @@ -78,7 +78,9 @@ class DirectoryStorage(Storage): # Replace this with `root_dir` when dropping Python 3.9 support escapedDirPrefix = os.path.join(glob.escape(self._directory), '') escapedDirPrefixLen = len(escapedDirPrefix) - for metadataFilename in glob.glob(f'{escapedDirPrefix}*.codearchiver-metadata'): + files = glob.glob(f'{escapedDirPrefix}*.codearchiver-metadata') + files.sort() + for metadataFilename in files: metadataFilename = metadataFilename[escapedDirPrefixLen:] _logger.info(f'Searching metadata {metadataFilename}') with self.open(metadataFilename, 'r') as fp: