@@ -1881,12 +1881,46 @@ mod tests {
18811881 check ! ( fs:: create_dir_all( & d2) ) ;
18821882 check ! ( check!( File :: create( & canary) ) . write( b"foo" ) ) ;
18831883 check ! ( symlink_junction( & d2, & dt. join( "d2" ) ) ) ;
1884+ check ! ( symlink_file( & canary, & d1. join( "canary" ) ) ) ;
18841885 check ! ( fs:: remove_dir_all( & d1) ) ;
18851886
18861887 assert ! ( !d1. is_dir( ) ) ;
18871888 assert ! ( canary. exists( ) ) ;
18881889 }
18891890
1891+ #[ test]
1892+ fn recursive_rmdir_of_symlink ( ) {
1893+ // test we do not recursively delete a symlink but only dirs.
1894+ let tmpdir = tmpdir ( ) ;
1895+ let link = tmpdir. join ( "d1" ) ;
1896+ let dir = tmpdir. join ( "d2" ) ;
1897+ let canary = dir. join ( "do_not_delete" ) ;
1898+ check ! ( fs:: create_dir_all( & dir) ) ;
1899+ check ! ( check!( File :: create( & canary) ) . write( b"foo" ) ) ;
1900+ check ! ( symlink_junction( & dir, & link) ) ;
1901+ check ! ( fs:: remove_dir_all( & link) ) ;
1902+
1903+ assert ! ( !link. is_dir( ) ) ;
1904+ assert ! ( canary. exists( ) ) ;
1905+ }
1906+
1907+ #[ test]
1908+ // only Windows makes a distinction between file and directory symlinks.
1909+ #[ cfg( windows) ]
1910+ fn recursive_rmdir_of_file_symlink ( ) {
1911+ let tmpdir = tmpdir ( ) ;
1912+ if !got_symlink_permission ( & tmpdir) { return } ;
1913+
1914+ let f1 = tmpdir. join ( "f1" ) ;
1915+ let f2 = tmpdir. join ( "f2" ) ;
1916+ check ! ( check!( File :: create( & f1) ) . write( b"foo" ) ) ;
1917+ check ! ( symlink_file( & f1, & f2) ) ;
1918+ match fs:: remove_dir_all ( & f2) {
1919+ Ok ( ..) => panic ! ( "wanted a failure" ) ,
1920+ Err ( ..) => { }
1921+ }
1922+ }
1923+
18901924 #[ test]
18911925 fn unicode_path_is_dir ( ) {
18921926 assert ! ( Path :: new( "." ) . is_dir( ) ) ;
0 commit comments