Skip to content

Commit 73b3fa8

Browse files
authored
Merge pull request #1011 from cgwalters/wipe-fix
install: Fix cleanup function to remove empty dirs too
2 parents ac27e42 + 31d44dd commit 73b3fa8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/src/install.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,7 @@ fn remove_all_in_dir_no_xdev(d: &Dir, mount_err: bool) -> Result<()> {
15701570
if etype == FileType::dir() {
15711571
if let Some(subdir) = open_dir_noxdev(d, &name)? {
15721572
remove_all_in_dir_no_xdev(&subdir, mount_err)?;
1573+
d.remove_dir(&name)?;
15731574
} else if mount_err {
15741575
anyhow::bail!("Found unexpected mount point {name:?}");
15751576
}
@@ -1951,4 +1952,22 @@ mod tests {
19511952
assert_eq!(r.kargs.len(), 1);
19521953
assert_eq!(r.kargs[0], "rd.lvm.lv=root");
19531954
}
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+
}
19541973
}

0 commit comments

Comments
 (0)