From a34c576c42c91859bd5752b45f380480d361a52e Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Thu, 2 Nov 2017 13:21:03 +0100 Subject: recursiveloader: Support restricting directory updates to mtime --- gemato/recursiveloader.py | 12 ++++++++++-- tests/test_recursiveloader.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py index 26ed811..2d78af6 100644 --- a/gemato/recursiveloader.py +++ b/gemato/recursiveloader.py @@ -824,7 +824,8 @@ class ManifestRecursiveLoader(object): return new_manifests - def update_entries_for_directory(self, path='', hashes=None): + def update_entries_for_directory(self, path='', hashes=None, + last_mtime=None): """ Update the Manifest entries for the contents of directory @path (top directory by default), recursively. Includes adding @@ -841,6 +842,12 @@ class ManifestRecursiveLoader(object): @hashes specifies the requested hash set. The effective value must be non-null since new entries can be created. + + If @last_mtime is not None, then only files whose mtime is newer + than that value (in st_mtime format) will be updated. Use this + option *only* if you can rely on mtimes being bumped + monotonically on modified files. Afterwards, the value + of @last_mtime should be put into the TIMESTAMP entry. """ if hashes is None: @@ -951,7 +958,8 @@ class ManifestRecursiveLoader(object): os.path.join(dirpath, f), fe, hashes=hashes, - expected_dev=self.manifest_device) + expected_dev=self.manifest_device, + last_mtime=last_mtime) if changed and mpath is not None: self.updated_manifests.add(mpath) diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py index a6fb283..40aeb2b 100644 --- a/tests/test_recursiveloader.py +++ b/tests/test_recursiveloader.py @@ -2756,3 +2756,20 @@ DATA test 11 MD5 5f8db599de986fab7a21625b7916589c os.path.join(self.dir, 'Manifest')) st = os.stat(os.path.join(self.dir, 'test')) m.assert_directory_verifies('', last_mtime=st.st_mtime) + + def test_update_entries_for_directory_old_mtime(self): + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(self.dir, 'Manifest'), + hashes=['MD5']) + m.update_entries_for_directory('', last_mtime=0) + self.assertEqual(m.find_path_entry('test').checksums['MD5'], + '6f8db599de986fab7a21625b7916589c') + + def test_update_entries_for_directory_new_mtime(self): + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(self.dir, 'Manifest'), + hashes=['MD5']) + st = os.stat(os.path.join(self.dir, 'test')) + m.update_entries_for_directory('', last_mtime=st.st_mtime) + self.assertEqual(m.find_path_entry('test').checksums['MD5'], + '5f8db599de986fab7a21625b7916589c') -- cgit v1.2.3