@@ -1940,12 +1940,46 @@ mod tests {
1940
1940
check ! ( fs:: create_dir_all( & d2) ) ;
1941
1941
check ! ( check!( File :: create( & canary) ) . write( b"foo" ) ) ;
1942
1942
check ! ( symlink_junction( & d2, & dt. join( "d2" ) ) ) ;
1943
+ let _ = symlink_file ( & canary, & d1. join ( "canary" ) ) ;
1943
1944
check ! ( fs:: remove_dir_all( & d1) ) ;
1944
1945
1945
1946
assert ! ( !d1. is_dir( ) ) ;
1946
1947
assert ! ( canary. exists( ) ) ;
1947
1948
}
1948
1949
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
+
1949
1983
#[ test]
1950
1984
fn unicode_path_is_dir ( ) {
1951
1985
assert ! ( Path :: new( "." ) . is_dir( ) ) ;
0 commit comments