From 485e4d6974b9bf6de162f5867f817845678fb353 Mon Sep 17 00:00:00 2001 From: Xerxes-2 Date: Sun, 23 Jun 2024 21:45:14 +1000 Subject: [PATCH] Refactor rename_without_overwriting to use tokio::task::spawn_blocking --- yazi-shared/src/fs/fns.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/yazi-shared/src/fs/fns.rs b/yazi-shared/src/fs/fns.rs index 99c8dcc3..7d17466e 100644 --- a/yazi-shared/src/fs/fns.rs +++ b/yazi-shared/src/fs/fns.rs @@ -54,8 +54,11 @@ pub async fn rename_without_overwriting( .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid path"))?; let new = U16CString::from_os_str(new.as_ref().as_os_str()) .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid path"))?; - let result = unsafe { MoveFileExW(old.as_ptr(), new.as_ptr(), 0) }; - if result != 0 { Ok(()) } else { Err(io::Error::last_os_error()) } + tokio::task::spawn_blocking(move || { + let result = unsafe { MoveFileExW(old.as_ptr(), new.as_ptr(), 0) }; + if result != 0 { Ok(()) } else { Err(io::Error::last_os_error()) } + }) + .await? } pub async fn symlink_realpath(path: &Path) -> Result {