diff options
author | Lars Wirzenius <liw@gytha> | 2008-04-12 21:55:50 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@gytha> | 2008-04-12 21:55:50 +0300 |
commit | 18eb0e836a382bcd6779a2befbb5dd76b9ca9bc2 (patch) | |
tree | 7b4710f7368234f7b2e52c74552b6f2b14c516b2 /obnam | |
parent | ddae06821a78a1279a4f3c22a01168f1db7423f1 (diff) | |
download | obnam-18eb0e836a382bcd6779a2befbb5dd76b9ca9bc2.tar.gz |
Added method for comparing file groups to see if they have changed since the previous backup.
Diffstat (limited to 'obnam')
-rw-r--r-- | obnam/app.py | 23 | ||||
-rw-r--r-- | obnam/appTests.py | 40 |
2 files changed, 63 insertions, 0 deletions
diff --git a/obnam/app.py b/obnam/app.py index 8b7ff752..6949fe78 100644 --- a/obnam/app.py +++ b/obnam/app.py @@ -148,6 +148,29 @@ class Application: return False return True + def filegroup_is_unchanged(self, fg, filenames, stat=os.stat): + """Is a filegroup unchanged from the previous generation? + + Given a filegroup and a list of files in the current directory, + return True if all files in the filegroup are unchanged from + the previous generation. + + The optional stat argument can be used by unit tests to + override the use of os.stat. + + """ + + for old_name in fg.get_names(): + if old_name not in filenames: + return False # file has been deleted + + old_stat = fg.get_stat(old_name) + new_stat = stat(old_name) + if not self.file_is_unchanged(old_stat, new_stat): + return False # file has changed + + return True # everything seems to be as before + 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 47b64578..d046be8a 100644 --- a/obnam/appTests.py +++ b/obnam/appTests.py @@ -199,6 +199,46 @@ class ApplicationUnchangedFileRecognitionTests(unittest.TestCase): self.failIf(self.app.file_is_unchanged(st1, st2)) +class ApplicationUnchangedFileGroupTests(unittest.TestCase): + + def setUp(self): + context = obnam.context.Context() + self.app = obnam.Application(context) + self.stats = { + "pink": obnam.utils.make_stat_result(st_mtime=42), + "pretty": obnam.utils.make_stat_result(st_mtime=105), + } + + def mock_stat(self, filename): + return self.stats[filename] + + def mock_filegroup(self, filenames): + fg = obnam.obj.FileGroupObject(id=obnam.obj.object_id_new()) + for filename in filenames: + st = self.mock_stat(filename) + fg.add_file(filename, st, None, None, None) + return fg + + def testSameFileGroupWhenAllFilesAreIdentical(self): + filenames = ["pink", "pretty"] + fg = self.mock_filegroup(filenames) + self.failUnless(self.app.filegroup_is_unchanged(fg, filenames, + stat=self.mock_stat)) + + def testChangedFileGroupWhenFileHasChanged(self): + filenames = ["pink", "pretty"] + fg = self.mock_filegroup(filenames) + self.stats["pink"] = obnam.utils.make_stat_result(st_mtime=1) + self.failIf(self.app.filegroup_is_unchanged(fg, filenames, + stat=self.mock_stat)) + + def testChangedFileGroupWhenFileHasBeenRemoved(self): + filenames = ["pink", "pretty"] + fg = self.mock_filegroup(filenames) + self.failIf(self.app.filegroup_is_unchanged(fg, filenames[:1], + stat=self.mock_stat)) + + class ApplicationFindFileByNameTests(unittest.TestCase): def setUp(self): |