diff --git a/native/src/base/files.rs b/native/src/base/files.rs index c8bdc278b..b792c89b6 100644 --- a/native/src/base/files.rs +++ b/native/src/base/files.rs @@ -326,11 +326,12 @@ impl Utf8CStr { pub fn set_attr<'a>(&'a self, attr: &'a FileAttr) -> OsResult<'a, ()> { unsafe { if !attr.is_symlink() { - libc::chmod(self.as_ptr(), (attr.st.st_mode & 0o777).as_()).check_os_err( - "chmod", - Some(self), - None, - )?; + if libc::chmod(self.as_ptr(), (attr.st.st_mode & 0o777).as_()) < 0 { + let self_attr = self.get_attr()?; + if !self_attr.is_symlink() { + return Err(OsError::last_os_error("chmod", Some(self), None)); + } + } } libc::lchown(self.as_ptr(), attr.st.st_uid, attr.st.st_gid).check_os_err( "lchown",