@@ -1790,6 +1790,46 @@ def test_copy_files(self):
17901790 regex = re .compile ("^copied 2 files to .*/target" )
17911791 self .assertTrue (regex .match (stdout ), "Pattern '%s' should be found in: %s" % (regex .pattern , stdout ))
17921792
1793+ def test_has_recursive_symlinks (self ):
1794+ """Test has_recursive_symlinks function"""
1795+ test_folder = tempfile .mkdtemp ()
1796+ self .assertFalse (ft .has_recursive_symlinks (test_folder ))
1797+ # Clasic Loop: Symlink to .
1798+ os .symlink ('.' , os .path .join (test_folder , 'self_link_dot' ))
1799+ self .assertTrue (ft .has_recursive_symlinks (test_folder ))
1800+ # Symlink to self
1801+ test_folder = tempfile .mkdtemp ()
1802+ os .symlink ('self_link' , os .path .join (test_folder , 'self_link' ))
1803+ self .assertTrue (ft .has_recursive_symlinks (test_folder ))
1804+ # Symlink from 2 folders up
1805+ test_folder = tempfile .mkdtemp ()
1806+ sub_folder = os .path .join (test_folder , 'sub1' , 'sub2' )
1807+ os .makedirs (sub_folder )
1808+ os .symlink (os .path .join ('..' , '..' ), os .path .join (sub_folder , 'uplink' ))
1809+ self .assertTrue (ft .has_recursive_symlinks (test_folder ))
1810+ # Non-issue: Symlink to sibling folders
1811+ test_folder = tempfile .mkdtemp ()
1812+ sub_folder = os .path .join (test_folder , 'sub1' , 'sub2' )
1813+ os .makedirs (sub_folder )
1814+ sibling_folder = os .path .join (test_folder , 'sub1' , 'sibling' )
1815+ os .mkdir (sibling_folder )
1816+ os .symlink ('sibling' , os .path .join (test_folder , 'sub1' , 'sibling_link' ))
1817+ os .symlink (os .path .join ('..' , 'sibling' ), os .path .join (test_folder , sub_folder , 'sibling_link' ))
1818+ self .assertFalse (ft .has_recursive_symlinks (test_folder ))
1819+ # Tricky case: Sibling symlink to folder starting with the same name
1820+ os .mkdir (os .path .join (test_folder , 'sub11' ))
1821+ os .symlink (os .path .join ('..' , 'sub11' ), os .path .join (test_folder , 'sub1' , 'trick_link' ))
1822+ self .assertFalse (ft .has_recursive_symlinks (test_folder ))
1823+ # Symlink cycle: sub1/cycle_2 -> sub2, sub2/cycle_1 -> sub1, ...
1824+ test_folder = tempfile .mkdtemp ()
1825+ sub_folder1 = os .path .join (test_folder , 'sub1' )
1826+ sub_folder2 = sub_folder = os .path .join (test_folder , 'sub2' )
1827+ os .mkdir (sub_folder1 )
1828+ os .mkdir (sub_folder2 )
1829+ os .symlink (os .path .join ('..' , 'sub2' ), os .path .join (sub_folder1 , 'cycle_1' ))
1830+ os .symlink (os .path .join ('..' , 'sub1' ), os .path .join (sub_folder2 , 'cycle_2' ))
1831+ self .assertTrue (ft .has_recursive_symlinks (test_folder ))
1832+
17931833 def test_copy_dir (self ):
17941834 """Test copy_dir function."""
17951835 testdir = os .path .dirname (os .path .abspath (__file__ ))
0 commit comments