def test_archive_corruption_case_actual(self, vault_mock): vault_file_one = self.vault.add(Branch.Staged, self.file_one) vault_file_two = self.vault.add(Branch.Limbo, self.file_two) walk = [(self.vault, File.FromFS(vault_file_one.path), VaultExc.PhysicalVaultFile("File is in Staged and can have to hardlinks if the file was archived with the stash option")), (self.vault, File.FromFS(vault_file_two.path), VaultExc.PhysicalVaultFile("File is in Limbo and has two hardlinks"))] dummy_walker = _DummyWalker(walk) dummy_persistence = MagicMock() Sweeper(dummy_walker, dummy_persistence, True) self.assertTrue(os.path.isfile(self.file_one)) self.assertTrue(os.path.isfile(vault_file_one.path)) self.assertTrue(os.path.isfile(self.file_two)) self.assertTrue(os.path.isfile(vault_file_two.path))
def test_keep_corruption_case_actual(self, vault_mock): vault_file_one = self.vault.add(Branch.Keep, self.file_one) vault_file_two = self.vault.add(Branch.Archive, self.file_two) vault_file_three = self.vault.add(Branch.Limbo, self.file_three) self.file_one.unlink() walk = [(self.vault, File.FromFS(vault_file_one.path), VaultExc.PhysicalVaultFile()), (self.vault, File.FromFS(vault_file_two.path), VaultExc.PhysicalVaultFile()), (self.vault, File.FromFS(vault_file_three.path), VaultExc.PhysicalVaultFile())] dummy_walker = _DummyWalker(walk) dummy_persistence = MagicMock() Sweeper(dummy_walker, dummy_persistence, True) self.assertFalse(os.path.isfile(self.file_one)) self.assertFalse(os.path.isfile(vault_file_one.path)) self.assertTrue(os.path.isfile(self.file_two)) self.assertTrue(os.path.isfile(vault_file_two.path)) self.assertTrue(os.path.isfile(self.file_three)) self.assertTrue(os.path.isfile(vault_file_three.path))
def test_limbo_deletion_threshold_not_passed_for_access(self, vault_mock): vault_file_one = self.vault.add(Branch.Limbo, self.file_one) self.file_one.unlink() walk = [(self.vault, make_file_seem_old_but_read_recently( vault_file_one.path), VaultExc.PhysicalVaultFile("File is in Limbo"))] dummy_walker = _DummyWalker(walk) dummy_persistence = MagicMock() Sweeper(dummy_walker, dummy_persistence, True) self.assertFalse(os.path.isfile(self.file_one)) self.assertTrue(os.path.isfile(vault_file_one.path))
def test_staged_not_deleted(self, vault_mock): vault_file_one = self.vault.add(Branch.Staged, self.file_one) self.file_one.unlink() walk = [(self.vault, make_file_seem_old( vault_file_one.path), VaultExc.PhysicalVaultFile())] dummy_walker = _DummyWalker(walk) dummy_persistence = MagicMock() Sweeper(dummy_walker, dummy_persistence, True) self.assertFalse(os.path.isfile(self.file_one)) self.assertTrue(os.path.isfile(vault_file_one.path))
def test_dryrun_basic(self, vault_mock): vault_file_one = self.vault.add(Branch.Keep, self.file_one) vault_file_two = self.vault.add(Branch.Archive, self.file_two) vault_file_three = self.vault.add(Branch.Limbo, self.file_three) walk = [(self.vault, make_file_seem_old(vault_file_one.path), VaultExc.PhysicalVaultFile()), (self.vault, make_file_seem_old(vault_file_two.path), VaultExc.PhysicalVaultFile()), (self.vault, make_file_seem_old(vault_file_three.path), VaultExc.PhysicalVaultFile()), (self.vault, make_file_seem_old(self.file_three), None)] dummy_walker = _DummyWalker(walk) dummy_persistence = MagicMock() Sweeper(dummy_walker, dummy_persistence, False) self.assertTrue(os.path.isfile(self.file_one)) self.assertTrue(os.path.isfile(self.file_two)) self.assertTrue(os.path.isfile(self.file_three)) self.assertTrue(os.path.isfile(vault_file_one.path)) self.assertTrue(os.path.isfile(vault_file_two.path)) self.assertTrue(os.path.isfile(vault_file_three.path))
def test_limbo_deletion_threshold_not_passed(self, vault_mock): vault_file_one = self.vault.add(Branch.Limbo, self.file_one) new_time = time.now() - config.deletion.limbo + time.delta(seconds=1) self.file_one.unlink() walk = [(self.vault, _DummyFile.FromFS(vault_file_one.path, idm, ctime=new_time, mtime=new_time, atime=new_time), VaultExc.PhysicalVaultFile("File is in Limbo"))] dummy_walker = _DummyWalker(walk) dummy_persistence = MagicMock() Sweeper(dummy_walker, dummy_persistence, True) self.assertFalse(os.path.isfile(self.file_one)) self.assertTrue(os.path.isfile(vault_file_one.path))