From 5e306d1ec63627716bc97626d2f754dc6de2a781 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Thu, 2 Nov 2017 09:59:58 +0100 Subject: verify: Include st_mtime in file metadata --- gemato/verify.py | 18 ++++++++++++++---- tests/test_verify.py | 6 +++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/gemato/verify.py b/gemato/verify.py index 538c998..3c5e9df 100644 --- a/gemato/verify.py +++ b/gemato/verify.py @@ -26,7 +26,8 @@ def get_file_metadata(path, hashes): exists. 4. st_size, if the file exists and is a regular file. Note that it may be 0 on some filesystems, so treat the value with caution. - 5. A dict of @hashes and their values, if the file exists and is + 5. st_mtime, if the file exists and is a regular file. + 6. A dict of @hashes and their values, if the file exists and is a regular file. Special __size__ member is added unconditionally. Note that the generator acquires resources, and does not release @@ -92,6 +93,9 @@ def get_file_metadata(path, hashes): # 4. st_size yield st.st_size + # 5. st_mtime + yield st.st_mtime + f = io.open(fd, 'rb') except: if opened: @@ -179,14 +183,17 @@ def verify_path(path, e, expected_dev=None): if st_size != 0 and st_size != e.size: return (False, [('__size__', e.size, st_size)]) - # 5. verify the real size from checksum data + # 5. skip st_mtime for now + st_mtime = next(g) + + # 6. verify the real size from checksum data checksums = next(g) diff = [] size = checksums.pop('__size__') if size != e.size: diff.append(('__size__', e.size, size)) - # 6. verify the checksums + # 7. verify the checksums for h in sorted(e.checksums): exp = e.checksums[h] got = checksums[h] @@ -244,7 +251,10 @@ def update_entry_for_path(path, e, hashes=None, expected_dev=None): # 4. get the apparent file size st_size = next(g) - # 5. get the checksums and real size + # 5. skip st_mtime for now + st_mtime = next(g) + + # 6. get the checksums and real size checksums = next(g) size = checksums.pop('__size__') if st_size != 0: diff --git a/tests/test_verify.py b/tests/test_verify.py index 7cc2a10..1656b23 100644 --- a/tests/test_verify.py +++ b/tests/test_verify.py @@ -244,7 +244,7 @@ class EmptyFileVerificationTest(unittest.TestCase): self.assertEqual(list(gemato.verify.get_file_metadata( self.path, hashes=['MD5', 'SHA1'])), [True, st.st_dev, (stat.S_IFREG, 'regular file'), - 0, { + 0, st.st_mtime, { 'MD5': 'd41d8cd98f00b204e9800998ecf8427e', 'SHA1': 'da39a3ee5e6b4b0d3255bfef95601890afd80709', '__size__': 0, @@ -448,7 +448,7 @@ class NonEmptyFileVerificationTest(unittest.TestCase): self.assertEqual(list(gemato.verify.get_file_metadata( self.path, hashes=['MD5', 'SHA1'])), [True, st.st_dev, (stat.S_IFREG, 'regular file'), - st.st_size, { + st.st_size, st.st_mtime, { 'MD5': '9e107d9d372bb6826bd81d3542a419d6', 'SHA1': '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12', '__size__': 43, @@ -628,7 +628,7 @@ class ProcFileVerificationTest(unittest.TestCase): self.assertEqual(list(gemato.verify.get_file_metadata( self.path, hashes=['MD5', 'SHA1'])), [True, st.st_dev, (stat.S_IFREG, 'regular file'), - st.st_size, { + st.st_size, st.st_mtime, { 'MD5': self.md5, 'SHA1': self.sha1, '__size__': self.size, -- cgit v1.2.3