From 8b0cf602b45a550a396f96ec9605fd3e7cfbe5c2 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Tue, 31 Oct 2017 17:05:13 +0100 Subject: recursiveloader: Optimize getting valid Manifest filenames --- gemato/recursiveloader.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py index 486a15c..52628ad 100644 --- a/gemato/recursiveloader.py +++ b/gemato/recursiveloader.py @@ -347,6 +347,9 @@ class ManifestRecursiveLoader(object): returned explicit False; True otherwise. """ + manifest_filenames = (gemato.compression + .get_potential_compressed_names('Manifest')) + entry_dict = self.get_file_entry_dict(path) it = os.walk(os.path.join(self.root_directory, path), onerror=gemato.util.throw_exception, @@ -396,8 +399,7 @@ class ManifestRecursiveLoader(object): fpath = os.path.join(relpath, f) # skip top-level Manifest, we obviously can't have # an entry for it - if fpath in (gemato.compression - .get_potential_compressed_names('Manifest')): + if fpath in manifest_filenames: continue fe = entry_dict.pop(fpath, None) ret &= self._verify_one_file(os.path.join(dirpath, f), @@ -697,8 +699,12 @@ class ManifestRecursiveLoader(object): hashes = self.hashes assert hashes is not None + manifest_filenames = (gemato.compression + .get_potential_compressed_names('Manifest')) + entry_dict = self.get_deduplicated_file_entry_dict_for_update( path) + dir_manifest_stack = [] it = os.walk(os.path.join(self.root_directory, path), onerror=gemato.util.throw_exception, followlinks=True) @@ -742,8 +748,7 @@ class ManifestRecursiveLoader(object): # check for unregistered Manifest new_manifests = set() - for mname in (gemato.compression - .get_potential_compressed_names('Manifest')): + for mname in manifest_filenames: if mname in filenames: fpath = os.path.join(relpath, mname) if fpath in self.loaded_manifests: @@ -769,16 +774,15 @@ class ManifestRecursiveLoader(object): continue fpath = os.path.join(relpath, f) - # skip top-level Manifest, we obviously can't have - # an entry for it - if fpath in (gemato.compression - .get_potential_compressed_names('Manifest')): - continue mpath, fe = entry_dict.pop(fpath, (None, None)) if fe is not None: if fe.tag in ('IGNORE', 'OPTIONAL'): continue else: + # skip top-level Manifest, we obviously can't have + # an entry for it + if fpath in manifest_filenames: + continue if f in new_manifests: cls = gemato.manifest.ManifestEntryMANIFEST # new Manifests go into the parent directory -- cgit v1.2.3