From 94b1ff674f0eb894cf0b0cbb644b4975dec926dc Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 10 Sep 2025 03:44:39 -0700 Subject: [PATCH] Allow calling remove_all on non-existence file --- native/src/base/files.rs | 11 ++++++++++- native/src/base/result.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/native/src/base/files.rs b/native/src/base/files.rs index fef451934..a70210ad8 100644 --- a/native/src/base/files.rs +++ b/native/src/base/files.rs @@ -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()?; diff --git a/native/src/base/result.rs b/native/src/base/result.rs index e6cae9cb9..6fe853ef2 100644 --- a/native/src/base/result.rs +++ b/native/src/base/result.rs @@ -281,7 +281,7 @@ impl LibcReturn for nix::Result { #[derive(Debug)] pub struct OsError<'a> { - errno: Errno, + pub errno: Errno, name: &'static str, arg1: Option<&'a str>, arg2: Option<&'a str>,