summaryrefslogtreecommitdiff
path: root/obnam
diff options
context:
space:
mode:
authorLars Wirzenius <liw@gytha>2008-04-12 21:16:47 +0300
committerLars Wirzenius <liw@gytha>2008-04-12 21:16:47 +0300
commit47863eb851c14a3661684b79448b24bc0d45f3a0 (patch)
treeaf8cdd4ee457e69925815835fbc3b17da6f6e591 /obnam
parent0a6af0841258611fe60a843fb300b6b64a5d5916 (diff)
downloadobnam-47863eb851c14a3661684b79448b24bc0d45f3a0.tar.gz
Added method for comparing stat results to see if a file has changed since the previous backup.
Diffstat (limited to 'obnam')
-rw-r--r--obnam/app.py16
-rw-r--r--obnam/appTests.py55
2 files changed, 71 insertions, 0 deletions
diff --git a/obnam/app.py b/obnam/app.py
index f1b5a416..5612ab29 100644
--- a/obnam/app.py
+++ b/obnam/app.py
@@ -132,6 +132,22 @@ class Application:
else:
i += 1
+ def file_is_unchanged(self, stat1, stat2):
+ """Has a file changed?
+
+ Given the stat results from the previous generation and the
+ current file, return True if the file is identical from the
+ previous generation (i.e., no new data to back up).
+
+ """
+
+ fields = ("mode", "dev", "nlink", "uid", "gid", "size", "mtime")
+ for field in fields:
+ field = "st_" + field
+ if getattr(stat1, field) != getattr(stat2, field):
+ return False
+ return True
+
def set_prevgen_filelist(self, filelist):
"""Set the Filelist object from the previous generation.
diff --git a/obnam/appTests.py b/obnam/appTests.py
index 24a982fb..47b64578 100644
--- a/obnam/appTests.py
+++ b/obnam/appTests.py
@@ -144,6 +144,61 @@ class ApplicationMakeFileGroupsTests(unittest.TestCase):
self.failIf("/" in fg.get_names()[0])
+class ApplicationUnchangedFileRecognitionTests(unittest.TestCase):
+
+ def setUp(self):
+ context = obnam.context.Context()
+ self.app = obnam.Application(context)
+
+ def testSameFileWhenStatIsIdentical(self):
+ st = obnam.utils.make_stat_result()
+ self.failUnless(self.app.file_is_unchanged(st, st))
+
+ def testSameFileWhenIrrelevantFieldsChange(self):
+ st1 = obnam.utils.make_stat_result()
+ st2 = obnam.utils.make_stat_result(st_ino=42,
+ st_atime=42,
+ st_blocks=42,
+ st_blksize=42,
+ st_rdev=42)
+ self.failUnless(self.app.file_is_unchanged(st1, st2))
+
+ def testChangedFileWhenDevChanges(self):
+ st1 = obnam.utils.make_stat_result()
+ st2 = obnam.utils.make_stat_result(st_dev=42)
+ self.failIf(self.app.file_is_unchanged(st1, st2))
+
+ def testChangedFileWhenModeChanges(self):
+ st1 = obnam.utils.make_stat_result()
+ st2 = obnam.utils.make_stat_result(st_mode=42)
+ self.failIf(self.app.file_is_unchanged(st1, st2))
+
+ def testChangedFileWhenNlinkChanges(self):
+ st1 = obnam.utils.make_stat_result()
+ st2 = obnam.utils.make_stat_result(st_nlink=42)
+ self.failIf(self.app.file_is_unchanged(st1, st2))
+
+ def testChangedFileWhenUidChanges(self):
+ st1 = obnam.utils.make_stat_result()
+ st2 = obnam.utils.make_stat_result(st_uid=42)
+ self.failIf(self.app.file_is_unchanged(st1, st2))
+
+ def testChangedFileWhenGidChanges(self):
+ st1 = obnam.utils.make_stat_result()
+ st2 = obnam.utils.make_stat_result(st_gid=42)
+ self.failIf(self.app.file_is_unchanged(st1, st2))
+
+ def testChangedFileWhenSizeChanges(self):
+ st1 = obnam.utils.make_stat_result()
+ st2 = obnam.utils.make_stat_result(st_size=42)
+ self.failIf(self.app.file_is_unchanged(st1, st2))
+
+ def testChangedFileWhenMtimeChanges(self):
+ st1 = obnam.utils.make_stat_result()
+ st2 = obnam.utils.make_stat_result(st_mtime=42)
+ self.failIf(self.app.file_is_unchanged(st1, st2))
+
+
class ApplicationFindFileByNameTests(unittest.TestCase):
def setUp(self):