def test_replace_file_with_hardlink(self): # If hardlink are supported, an existing file should be replaced by a # symlink. source = self.tmppath("test_path") with open(source, "wt") as fh: fh.write("source") dest = self.tmppath("dest") with open(dest, "a"): pass s = HardlinkFile(source) s.copy(dest, skip_if_older=False) if self.hardlink_supported: source_stat = os.stat(source) dest_stat = os.stat(dest) self.assertEqual(source_stat.st_dev, dest_stat.st_dev) self.assertEqual(source_stat.st_ino, dest_stat.st_ino) else: self.assertTrue(os.path.isfile(dest)) with open(dest) as f: content = f.read() self.assertEqual(content, "source")
def test_replace_file_with_hardlink(self): # If hardlink are supported, an existing file should be replaced by a # symlink. source = self.tmppath('test_path') with open(source, 'wt') as fh: fh.write('source') dest = self.tmppath('dest') with open(dest, 'a'): pass s = HardlinkFile(source) s.copy(dest, skip_if_older=False) if self.hardlink_supported: source_stat = os.stat(source) dest_stat = os.stat(dest) self.assertEqual(source_stat.st_dev, dest_stat.st_dev) self.assertEqual(source_stat.st_ino, dest_stat.st_ino) else: self.assertTrue(os.path.isfile(dest)) with open(dest) as f: content = f.read() self.assertEqual(content, 'source')
def test_noop(self): if not self.hardlink_supported: raise unittest.SkipTest("hardlink not supported") source = self.tmppath("source") dest = self.tmppath("dest") with open(source, "a"): pass os.link(source, dest) s = HardlinkFile(source) self.assertFalse(s.copy(dest)) source_stat = os.lstat(source) dest_stat = os.lstat(dest) self.assertEqual(source_stat.st_dev, dest_stat.st_dev) self.assertEqual(source_stat.st_ino, dest_stat.st_ino)
def test_hardlink_file(self): source = self.tmppath("test_path") with open(source, "wt") as fh: fh.write("Hello world") s = HardlinkFile(source) dest = self.tmppath("hardlink") self.assertTrue(s.copy(dest)) if self.hardlink_supported: source_stat = os.stat(source) dest_stat = os.stat(dest) self.assertEqual(source_stat.st_dev, dest_stat.st_dev) self.assertEqual(source_stat.st_ino, dest_stat.st_ino) else: self.assertTrue(os.path.isfile(dest)) with open(dest) as f: content = f.read() self.assertEqual(content, "Hello world")
def test_replace_hardlink(self): if not self.hardlink_supported: raise unittest.SkipTest('hardlink not supported') source = self.tmppath('source') with open(source, 'a'): pass dest = self.tmppath('dest') os.link(source, dest) s = HardlinkFile(source) self.assertFalse(s.copy(dest)) source_stat = os.lstat(source) dest_stat = os.lstat(dest) self.assertEqual(source_stat.st_dev, dest_stat.st_dev) self.assertEqual(source_stat.st_ino, dest_stat.st_ino)
def test_noop(self): if not self.hardlink_supported: raise unittest.SkipTest('hardlink not supported') source = self.tmppath('source') dest = self.tmppath('dest') with open(source, 'a'): pass os.link(source, dest) s = HardlinkFile(source) self.assertFalse(s.copy(dest)) source_stat = os.lstat(source) dest_stat = os.lstat(dest) self.assertEqual(source_stat.st_dev, dest_stat.st_dev) self.assertEqual(source_stat.st_ino, dest_stat.st_ino)
def test_hardlink_file(self): source = self.tmppath('test_path') with open(source, 'wt') as fh: fh.write('Hello world') s = HardlinkFile(source) dest = self.tmppath('hardlink') self.assertTrue(s.copy(dest)) if self.hardlink_supported: source_stat = os.stat(source) dest_stat = os.stat(dest) self.assertEqual(source_stat.st_dev, dest_stat.st_dev) self.assertEqual(source_stat.st_ino, dest_stat.st_ino) else: self.assertTrue(os.path.isfile(dest)) with open(dest) as f: content = f.read() self.assertEqual(content, 'Hello world')