File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -1570,6 +1570,7 @@ fn remove_all_in_dir_no_xdev(d: &Dir, mount_err: bool) -> Result<()> {
1570
1570
if etype == FileType :: dir ( ) {
1571
1571
if let Some ( subdir) = open_dir_noxdev ( d, & name) ? {
1572
1572
remove_all_in_dir_no_xdev ( & subdir, mount_err) ?;
1573
+ d. remove_dir ( & name) ?;
1573
1574
} else if mount_err {
1574
1575
anyhow:: bail!( "Found unexpected mount point {name:?}" ) ;
1575
1576
}
@@ -1951,4 +1952,22 @@ mod tests {
1951
1952
assert_eq ! ( r. kargs. len( ) , 1 ) ;
1952
1953
assert_eq ! ( r. kargs[ 0 ] , "rd.lvm.lv=root" ) ;
1953
1954
}
1955
+
1956
+ // As this is a unit test we don't try to test mountpoints, just verify
1957
+ // that we have the equivalent of rm -rf *
1958
+ #[ test]
1959
+ fn test_remove_all_noxdev ( ) -> Result < ( ) > {
1960
+ let td = cap_std_ext:: cap_tempfile:: TempDir :: new ( cap_std:: ambient_authority ( ) ) ?;
1961
+
1962
+ td. create_dir_all ( "foo/bar/baz" ) ?;
1963
+ td. write ( "foo/bar/baz/test" , b"sometest" ) ?;
1964
+ td. symlink_contents ( "/absolute-nonexistent-link" , "somelink" ) ?;
1965
+ td. write ( "toptestfile" , b"othertestcontents" ) ?;
1966
+
1967
+ remove_all_in_dir_no_xdev ( & td, true ) . unwrap ( ) ;
1968
+
1969
+ assert_eq ! ( td. entries( ) ?. count( ) , 0 ) ;
1970
+
1971
+ Ok ( ( ) )
1972
+ }
1954
1973
}
You can’t perform that action at this time.
0 commit comments