Refactor rename_without_overwriting to use tokio::task::spawn_blocking

This commit is contained in:
Xerxes-2 2024-06-23 21:45:14 +10:00
parent f72a6fae6e
commit 485e4d6974

View file

@ -54,8 +54,11 @@ pub async fn rename_without_overwriting(
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid path"))?; .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid path"))?;
let new = U16CString::from_os_str(new.as_ref().as_os_str()) let new = U16CString::from_os_str(new.as_ref().as_os_str())
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid path"))?; .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid path"))?;
let result = unsafe { MoveFileExW(old.as_ptr(), new.as_ptr(), 0) }; tokio::task::spawn_blocking(move || {
if result != 0 { Ok(()) } else { Err(io::Error::last_os_error()) } 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<PathBuf> { pub async fn symlink_realpath(path: &Path) -> Result<PathBuf> {