@@ -1881,12 +1881,46 @@ mod tests {
1881
1881
check ! ( fs:: create_dir_all( & d2) ) ;
1882
1882
check ! ( check!( File :: create( & canary) ) . write( b"foo" ) ) ;
1883
1883
check ! ( symlink_junction( & d2, & dt. join( "d2" ) ) ) ;
1884
+ check ! ( symlink_file( & canary, & d1. join( "canary" ) ) ) ;
1884
1885
check ! ( fs:: remove_dir_all( & d1) ) ;
1885
1886
1886
1887
assert ! ( !d1. is_dir( ) ) ;
1887
1888
assert ! ( canary. exists( ) ) ;
1888
1889
}
1889
1890
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
+
1890
1924
#[ test]
1891
1925
fn unicode_path_is_dir ( ) {
1892
1926
assert ! ( Path :: new( "." ) . is_dir( ) ) ;
0 commit comments