diff --git a/pungi/linker.py b/pungi/linker.py index 0bcadc41..097e52b1 100644 --- a/pungi/linker.py +++ b/pungi/linker.py @@ -228,20 +228,7 @@ class Linker(kobo.log.LoggingBase): raise ValueError("Unknown link_type: %s" % link_type) def link(self, src, dst, link_type="hardlink-or-copy"): - """Link directories recursively.""" - if os.path.isfile(src) or os.path.islink(src): - self._link_file(src, dst, link_type) - return + if os.path.isdir(src): + raise RuntimeError("Linking directories recursively is not supported") - if os.path.isfile(dst): - raise OSError(errno.EEXIST, "File exists") - - if not self.test: - if not os.path.exists(dst): - makedirs(dst) - shutil.copystat(src, dst) - - for i in os.listdir(src): - src_path = os.path.join(src, i) - dst_path = os.path.join(dst, i) - self.link(src_path, dst_path, link_type) + self._link_file(src, dst, link_type) diff --git a/tests/test_linker.py b/tests/test_linker.py index 87c5a3c1..7dcd74d9 100644 --- a/tests/test_linker.py +++ b/tests/test_linker.py @@ -280,70 +280,3 @@ class TestLinkerLink(TestLinkerBase): self.file2, link_type="hardlink-or-copy", ) - - def test_link_dir_hardlink(self): - self.linker.link(self.src_dir, self.dst_dir, link_type="hardlink") - self.assertTrue(os.path.isfile(self.dst_file1)) - self.assertTrue(self.same_inode(self.file1, self.dst_file1)) - self.assertTrue(self.same_inode(self.file3, self.dst_file3)) - self.assertSameStat( - os.path.dirname(self.file3), os.path.dirname(self.dst_file3) - ) - - # always preserve symlinks - self.assertEqual(os.readlink(self.dst_symlink1), "../file1") - self.assertEqual(os.readlink(self.dst_symlink2), "subdir") - self.assertEqual(os.readlink(self.dst_symlink3), "does-not-exist") - - def test_link_dir_copy(self): - self.linker.link(self.src_dir, self.dst_dir, link_type="copy") - self.assertTrue(os.path.isfile(self.dst_file1)) - self.assertFalse(self.same_inode(self.file1, self.dst_file1)) - self.assertFalse(self.same_inode(self.file3, self.dst_file3)) - self.assertSameStat( - os.path.dirname(self.file3), os.path.dirname(self.dst_file3) - ) - - # always preserve symlinks - self.assertEqual(os.readlink(self.dst_symlink1), "../file1") - self.assertEqual(os.readlink(self.dst_symlink2), "subdir") - self.assertEqual(os.readlink(self.dst_symlink3), "does-not-exist") - - def test_link_dir_copy_test_mode(self): - # turn test mode on - self.linker = linker.Linker(logger=self.logger, test=True) - self.linker.link(self.src_dir, self.dst_dir, link_type="copy") - - # dst_dir should not even exist - self.assertFalse(os.path.isdir(self.dst_dir)) - - def test_link_dir_symlink(self): - self.linker.link(self.src_dir, self.dst_dir, link_type="symlink") - self.assertTrue(os.path.isfile(self.dst_file1)) - self.assertTrue(os.path.islink(self.dst_file1)) - self.assertTrue(os.path.isdir(os.path.dirname(self.file3))) - - # always preserve symlinks - self.assertEqual(os.readlink(self.dst_symlink1), "../file1") - self.assertEqual(os.readlink(self.dst_symlink2), "subdir") - self.assertEqual(os.readlink(self.dst_symlink3), "does-not-exist") - - def test_link_dir_abspath_symlink(self): - self.linker.link(self.src_dir, self.dst_dir, link_type="abspath-symlink") - self.assertTrue(os.path.isfile(self.dst_file1)) - self.assertTrue(os.path.islink(self.dst_file1)) - self.assertEqual(os.readlink(self.dst_file1), self.file1) - self.assertSameStat( - os.path.dirname(self.file3), os.path.dirname(self.dst_file3) - ) - self.assertTrue(os.path.isdir(os.path.dirname(self.file3))) - - # always preserve symlinks - self.assertEqual(os.readlink(self.dst_symlink1), "../file1") - self.assertEqual(os.readlink(self.dst_symlink2), "subdir") - self.assertEqual(os.readlink(self.dst_symlink3), "does-not-exist") - - def test_copy_preserve_hardlinks(self): - self.assertTrue(self.same_inode(self.file1, self.hardlink1)) - self.linker.link(self.src_dir, self.dst_dir, link_type="copy") - self.assertTrue(self.same_inode(self.dst_file1, self.dst_hardlink1))