summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-11-02 13:14:04 +0100
committerMichał Górny <mgorny@gentoo.org>2017-11-02 13:14:04 +0100
commitafde52b89740f025d1b7aadbd6ec5fb2e5a43f03 (patch)
tree5ad71f3c33073978cf8271ffd578b40b4ab870fc
parentaeb42b5b74b4a92d63a201b5f1306cfcd42ed3ae (diff)
downloadgemato-afde52b89740f025d1b7aadbd6ec5fb2e5a43f03.tar.gz
recursiveloader: Support specifying mtime for verification
-rw-r--r--gemato/recursiveloader.py19
-rw-r--r--tests/test_recursiveloader.py25
2 files changed, 38 insertions, 6 deletions
diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py
index ed7d034..26ed811 100644
--- a/gemato/recursiveloader.py
+++ b/gemato/recursiveloader.py
@@ -362,9 +362,11 @@ class ManifestRecursiveLoader(object):
out[fullpath] = e
return out
- def _verify_one_file(self, path, relpath, e, fail_handler, warn_handler):
+ def _verify_one_file(self, path, relpath, e, fail_handler,
+ warn_handler, last_mtime):
ret, diff = gemato.verify.verify_path(path, e,
- expected_dev=self.manifest_device)
+ expected_dev=self.manifest_device,
+ last_mtime=last_mtime)
if not ret:
if e is not None and e.tag in ('MISC', 'OPTIONAL'):
@@ -380,7 +382,7 @@ class ManifestRecursiveLoader(object):
def assert_directory_verifies(self, path='',
fail_handler=gemato.util.throw_exception,
- warn_handler=None):
+ warn_handler=None, last_mtime=None):
"""
Verify the complete directory tree starting at @path (relative
to top Manifest directory). Includes testing for stray files.
@@ -400,6 +402,11 @@ class ManifestRecursiveLoader(object):
If none of the handlers raise exceptions, the function returns
boolean. It returns False if at least one of the handler calls
returned explicit False; True otherwise.
+
+ If @last_mtime is not None, then only files whose mtime is newer
+ than that value (in st_mtime format) will be checked. Use this
+ option *only* if mtimes can not be manipulated (i.e. do not use
+ it with 'rsync --times')!
"""
manifest_filenames = (gemato.compression
@@ -440,7 +447,7 @@ class ManifestRecursiveLoader(object):
skip_dirs.append(d)
else:
ret &= self._verify_one_file(os.path.join(dirpath, d),
- dpath, de, fail_handler, warn_handler)
+ dpath, de, fail_handler, warn_handler, last_mtime)
# skip scanning ignored directories
for d in skip_dirs:
@@ -458,13 +465,13 @@ class ManifestRecursiveLoader(object):
continue
fe = entry_dict.pop(fpath, None)
ret &= self._verify_one_file(os.path.join(dirpath, f),
- fpath, fe, fail_handler, warn_handler)
+ fpath, fe, fail_handler, warn_handler, last_mtime)
# check for missing files
for relpath, e in entry_dict.items():
syspath = os.path.join(self.root_directory, relpath)
ret &= self._verify_one_file(syspath, relpath, e,
- fail_handler, warn_handler)
+ fail_handler, warn_handler, last_mtime)
return ret
diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py
index a5ee83a..a6fb283 100644
--- a/tests/test_recursiveloader.py
+++ b/tests/test_recursiveloader.py
@@ -2731,3 +2731,28 @@ DATA c 0 MD5 d41d8cd98f00b204e9800998ecf8427e
e.path for e in m.loaded_manifests['a/Manifest'].entries),
['c'])
m.assert_directory_verifies()
+
+
+class ManifestMTimeTests(TempDirTestCase):
+ """
+ Tests for mtime-limited verification/update.
+ """
+
+ FILES = {
+ 'Manifest': u'''
+DATA test 11 MD5 5f8db599de986fab7a21625b7916589c
+''',
+ 'test': u'test string',
+ }
+
+ def test_assert_directory_verifies_old_mtime(self):
+ m = gemato.recursiveloader.ManifestRecursiveLoader(
+ os.path.join(self.dir, 'Manifest'))
+ self.assertRaises(gemato.exceptions.ManifestMismatch,
+ m.assert_directory_verifies, '', last_mtime=0)
+
+ def test_assert_directory_verifies_new_mtime(self):
+ m = gemato.recursiveloader.ManifestRecursiveLoader(
+ os.path.join(self.dir, 'Manifest'))
+ st = os.stat(os.path.join(self.dir, 'test'))
+ m.assert_directory_verifies('', last_mtime=st.st_mtime)