diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-10-29 14:43:11 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2017-10-29 14:43:11 +0100 |
commit | 442950a07eeec9fbee105241c1edf07d834f110c (patch) | |
tree | a7f1aa8339faa4e9fa7e02629f89d0e9c1497bf9 | |
parent | dd521bd834e448628a286d067c2d35c4bf38f786 (diff) | |
download | gemato-442950a07eeec9fbee105241c1edf07d834f110c.tar.gz |
recursiveloader: Support forcing Manifest update
-rw-r--r-- | gemato/recursiveloader.py | 11 | ||||
-rw-r--r-- | tests/test_recursiveloader.py | 26 |
2 files changed, 34 insertions, 3 deletions
diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py index 447e2d4..20fbb0b 100644 --- a/gemato/recursiveloader.py +++ b/gemato/recursiveloader.py @@ -400,7 +400,7 @@ class ManifestRecursiveLoader(object): return ret - def save_manifests(self, hashes=None): + def save_manifests(self, hashes=None, force=False): """ Save the Manifests modified since the last save_manifests() call. @@ -410,10 +410,15 @@ class ManifestRecursiveLoader(object): specified in ManifestLoader constructor is used. If that one is None as well, the routine reuses the existing hash set in the entry. + + If @force is True, all Manifests will be rewritten even + if they were not modified. """ if hashes is None: hashes = self.hashes + if force: + self.load_manifests_for_path('', recursive=True) fixed_manifests = set() for mpath, relpath, m in self._iter_manifests_for_path('', @@ -423,7 +428,7 @@ class ManifestRecursiveLoader(object): continue fullpath = os.path.join(relpath, e.path) - if fullpath not in self.updated_manifests: + if not force and fullpath not in self.updated_manifests: continue gemato.verify.update_entry_for_path( @@ -439,7 +444,7 @@ class ManifestRecursiveLoader(object): self.updated_manifests.add(mpath) # we've apparently modified this Manifest, so store it now - if mpath in self.updated_manifests: + if force or mpath in self.updated_manifests: self.save_manifest(mpath) # now, discard all the Manifests whose entries we've updated diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py index e257a10..1e9b186 100644 --- a/tests/test_recursiveloader.py +++ b/tests/test_recursiveloader.py @@ -348,6 +348,32 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e 'r', encoding='utf8') as f: self.assertEqual(f.read(), self.FILES['Manifest'].lstrip()) + def test_save_manifests_unmodified(self): + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(self.dir, 'Manifest')) + m.save_manifests() + with io.open(os.path.join(self.dir, 'Manifest'), + 'r', encoding='utf8') as f: + self.assertEqual(f.read(), self.FILES['Manifest']) + with io.open(os.path.join(self.dir, 'sub/Manifest'), + 'r', encoding='utf8') as f: + self.assertEqual(f.read(), self.FILES['sub/Manifest']) + with io.open(os.path.join(self.dir, 'other/Manifest'), + 'r', encoding='utf8') as f: + self.assertEqual(f.read(), self.FILES['other/Manifest']) + + def test_save_manifests_force(self): + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(self.dir, 'Manifest')) + m.save_manifests(force=True) + # Manifest checksums change + with io.open(os.path.join(self.dir, 'Manifest'), + 'r', encoding='utf8') as f: + self.assertNotEqual(f.read(), self.FILES['Manifest']) + with io.open(os.path.join(self.dir, 'sub/Manifest'), + 'r', encoding='utf8') as f: + self.assertNotEqual(f.read(), self.FILES['sub/Manifest']) + def test_update_entry_for_path(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) |