@@ -1940,12 +1940,46 @@ mod tests {
19401940 check ! ( fs:: create_dir_all( & d2) ) ;
19411941 check ! ( check!( File :: create( & canary) ) . write( b"foo" ) ) ;
19421942 check ! ( symlink_junction( & d2, & dt. join( "d2" ) ) ) ;
1943+ let _ = symlink_file ( & canary, & d1. join ( "canary" ) ) ;
19431944 check ! ( fs:: remove_dir_all( & d1) ) ;
19441945
19451946 assert ! ( !d1. is_dir( ) ) ;
19461947 assert ! ( canary. exists( ) ) ;
19471948 }
19481949
1950+ #[ test]
1951+ fn recursive_rmdir_of_symlink ( ) {
1952+ // test we do not recursively delete a symlink but only dirs.
1953+ let tmpdir = tmpdir ( ) ;
1954+ let link = tmpdir. join ( "d1" ) ;
1955+ let dir = tmpdir. join ( "d2" ) ;
1956+ let canary = dir. join ( "do_not_delete" ) ;
1957+ check ! ( fs:: create_dir_all( & dir) ) ;
1958+ check ! ( check!( File :: create( & canary) ) . write( b"foo" ) ) ;
1959+ check ! ( symlink_junction( & dir, & link) ) ;
1960+ check ! ( fs:: remove_dir_all( & link) ) ;
1961+
1962+ assert ! ( !link. is_dir( ) ) ;
1963+ assert ! ( canary. exists( ) ) ;
1964+ }
1965+
1966+ #[ test]
1967+ // only Windows makes a distinction between file and directory symlinks.
1968+ #[ cfg( windows) ]
1969+ fn recursive_rmdir_of_file_symlink ( ) {
1970+ let tmpdir = tmpdir ( ) ;
1971+ if !got_symlink_permission ( & tmpdir) { return } ;
1972+
1973+ let f1 = tmpdir. join ( "f1" ) ;
1974+ let f2 = tmpdir. join ( "f2" ) ;
1975+ check ! ( check!( File :: create( & f1) ) . write( b"foo" ) ) ;
1976+ check ! ( symlink_file( & f1, & f2) ) ;
1977+ match fs:: remove_dir_all ( & f2) {
1978+ Ok ( ..) => panic ! ( "wanted a failure" ) ,
1979+ Err ( ..) => { }
1980+ }
1981+ }
1982+
19491983 #[ test]
19501984 fn unicode_path_is_dir ( ) {
19511985 assert ! ( Path :: new( "." ) . is_dir( ) ) ;
0 commit comments