From dde7324e3fc489b4cc0152ac85dff25ec3f8752e Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Tue, 20 May 2025 07:31:57 +0200 Subject: [PATCH] mv: use bool instead of Result as return type for can_delete_file function --- src/uu/mv/src/mv.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 7a7b21f93..edfa505c5 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -698,8 +698,8 @@ fn rename_with_fallback( // 1. Files are on different devices (EXDEV error) // 2. On Windows, if the target file exists and source file is opened by another process // (MoveFileExW fails with "Access Denied" even if the source file has FILE_SHARE_DELETE permission) - let should_fallback = matches!(err.raw_os_error(), Some(EXDEV)) - || (from.is_file() && can_delete_file(from).unwrap_or(false)); + let should_fallback = + matches!(err.raw_os_error(), Some(EXDEV)) || (from.is_file() && can_delete_file(from)); if !should_fallback { return Err(err); } @@ -864,7 +864,7 @@ fn is_empty_dir(path: &Path) -> bool { /// Checks if a file can be deleted by attempting to open it with delete permissions. #[cfg(windows)] -fn can_delete_file(path: &Path) -> Result { +fn can_delete_file(path: &Path) -> bool { use std::{ os::windows::ffi::OsStrExt as _, ptr::{null, null_mut}, @@ -897,19 +897,19 @@ fn can_delete_file(path: &Path) -> Result { }; if handle == INVALID_HANDLE_VALUE { - return Err(io::Error::last_os_error()); + return false; } unsafe { CloseHandle(handle) }; - Ok(true) + true } #[cfg(not(windows))] -fn can_delete_file(_: &Path) -> Result { +fn can_delete_file(_: &Path) -> bool { // On non-Windows platforms, always return false to indicate that we don't need // to try the copy+delete fallback. This is because on Unix-like systems, // rename() failing with errors other than EXDEV means the operation cannot // succeed even with a copy+delete approach (e.g. permission errors). - Ok(false) + false }