示例#1
0
  def test_symlink(self):
    # Test that symlinks and hard links are scanned and restored correctly
    if not FSC.supports_symbolic_links():
      return

    backup = Mock.MockBackup(self.fsc.get_home())
    ctx = backup.start_increment("for restoring")

    #
    # Scan the files
    #
    f1 = FSC.FSCFile(u"kuku")
    f2 = FSC.FSCSymlink(u"file1")
    file_data = {u"file1": f1, u"file2": f2, u"file3": f1, u"file4": f2}
    self.fsc.reset()
    self.fsc.add_files(file_data)

    # Scan the directory structure
    basedir = Nodes.Directory(backup, None, self.fsc.get_home())
    ep = EP.ExclusionProcessor(self.fsc.get_home())
    basedir.scan(ctx, None, ep)
    digest = basedir.get_digest()
    level = basedir.get_level()
    stats = basedir.get_stats()
    
    # Try to restore
    self.fsc.reset()
    restore_dir = Nodes.Directory(backup, None, self.fsc.get_home())
    restore_dir.set_digest(digest)
    restore_dir.set_level(level)
    restore_dir.set_stats(stats)
    restore_dir.restore(ctx)

    self.failUnless(self.fsc.test_files(file_data))
示例#2
0
  def test_hlink(self):
    # Test that hard links are correctly identified and restored
    if not FSC.supports_hard_links():
      return

    backup = Mock.MockBackup(self.fsc.get_home())
    #
    # Create two files linking to the same inode
    #
    ctx = backup.start_increment("")
    self.fsc.add_files({u"file1": ""})
    self.fsc.link(u"file1", u"file2")
    
    root_node = Nodes.Directory(backup, None, self.fsc.get_home())
    file1_node = Nodes.File(backup, root_node, u"file1")
    file2_node = Nodes.File(backup, root_node, u"file2")
    file1_node.compute_stats()
    file2_node.compute_stats()
    file1_stat = file1_node.get_stats()
    file2_stat = file2_node.get_stats()

    # Hardlinked files should have the same stat.
    self.assertEquals(file1_stat, file2_stat)
    #
    # Scan the files...
    #
    self.assertEquals(file1_node.scan_hlink(ctx), False)
    file1_node.compute_stats()
    file1_node.scan(ctx, None)
    file1_node.update_hlink(ctx)
    self.assertEquals(file2_node.scan_hlink(ctx), True)
    file2_node.compute_stats()
    file2_node.scan(ctx, None)
    file2_node.update_hlink(ctx)
    backup.finalize_increment()
    #
    # Test that restore works...
    #
    self.fsc.reset()
    ctx = backup.start_restore(0)
    #self.assertEquals(file1_node.restore_hlink(ctx,file1_stat), False)
    file1_node.restore(ctx)
    self.assertEquals(file2_node.restore_hlink(ctx), True)
    #
    # Test that the linked file exists and that it is a hard link
    #
    self.assertEquals(self.fsc.test_link(u"file1", u"file2"), True)