fix: make unmount idempotent by ignoring "not mounted" errors

This commit is contained in:
Aiden McClelland
2026-03-09 23:59:38 -06:00
parent ccf6fa34b1
commit 2586f841b8

View File

@@ -52,13 +52,19 @@ pub async fn bind<P0: AsRef<Path>, P1: AsRef<Path>>(
pub async fn unmount<P: AsRef<Path>>(mountpoint: P, lazy: bool) -> Result<(), Error> { pub async fn unmount<P: AsRef<Path>>(mountpoint: P, lazy: bool) -> Result<(), Error> {
tracing::debug!("Unmounting {}.", mountpoint.as_ref().display()); tracing::debug!("Unmounting {}.", mountpoint.as_ref().display());
let mut cmd = tokio::process::Command::new("umount"); let mut cmd = tokio::process::Command::new("umount");
cmd.env("LANG", "C.UTF-8");
if lazy { if lazy {
cmd.arg("-l"); cmd.arg("-l");
} }
cmd.arg(mountpoint.as_ref()) match cmd
.arg(mountpoint.as_ref())
.invoke(crate::ErrorKind::Filesystem) .invoke(crate::ErrorKind::Filesystem)
.await?; .await
Ok(()) {
Ok(_) => Ok(()),
Err(e) if e.to_string().contains("not mounted") => Ok(()),
Err(e) => Err(e),
}
} }
/// Unmounts all mountpoints under (and including) the given path, in reverse /// Unmounts all mountpoints under (and including) the given path, in reverse