Allow calling remove_all on non-existence file

This commit is contained in:
topjohnwu
2025-09-10 03:44:39 -07:00
parent 111136733a
commit 94b1ff674f
2 changed files with 11 additions and 2 deletions

View File

@@ -407,7 +407,16 @@ impl Utf8CStr {
// We should treat these as application logic and log ASAP, so return LoggedResult.
impl Utf8CStr {
pub fn remove_all(&self) -> LoggedResult<()> {
let attr = self.get_attr()?;
let attr = match self.get_attr() {
Ok(attr) => attr,
Err(e) => {
return match e.errno {
// Allow calling remove_all on non-existence file
Errno::ENOENT => Ok(()),
_ => Err(e)?,
};
}
};
if attr.is_dir() {
let dir = Directory::open(self)?;
dir.remove_all()?;

View File

@@ -281,7 +281,7 @@ impl<T> LibcReturn for nix::Result<T> {
#[derive(Debug)]
pub struct OsError<'a> {
errno: Errno,
pub errno: Errno,
name: &'static str,
arg1: Option<&'a str>,
arg2: Option<&'a str>,