diff --git a/fusio/Cargo.toml b/fusio/Cargo.toml index bdc47de..700b312 100644 --- a/fusio/Cargo.toml +++ b/fusio/Cargo.toml @@ -80,7 +80,7 @@ hyper = { version = "1", optional = true, default-features = false, features = [ "http2", ] } itertools = { version = "0.13" } -monoio = { version = "0.2", optional = true } +monoio = { version = "0.2", optional = true, features = ["sync"] } object_store = { version = "0.11", optional = true, features = ["aws"] } percent-encoding = { version = "2", default-features = false } quick-xml = { version = "0.36", features = [ diff --git a/fusio/src/error.rs b/fusio/src/error.rs index 550709a..973f4b2 100644 --- a/fusio/src/error.rs +++ b/fusio/src/error.rs @@ -22,6 +22,9 @@ pub enum Error { Wasm { message: String, }, + #[cfg(feature = "monoio")] + #[error("monoio JoinHandle was canceled")] + MonoIOJoinCancel, #[error(transparent)] Other(#[from] BoxedError), } @@ -34,3 +37,8 @@ pub(crate) fn wasm_err(js_val: js_sys::wasm_bindgen::JsValue) -> Error { message: format!("{js_val:?}"), } } + +#[cfg(feature = "monoio")] +pub(crate) fn monoio_join_err(_: monoio::blocking::JoinError) -> Error { + Error::MonoIOJoinCancel +} diff --git a/fusio/src/impls/disk/monoio/fs.rs b/fusio/src/impls/disk/monoio/fs.rs index 229010a..3bfacdd 100644 --- a/fusio/src/impls/disk/monoio/fs.rs +++ b/fusio/src/impls/disk/monoio/fs.rs @@ -2,9 +2,11 @@ use std::{fs, fs::create_dir_all}; use async_stream::stream; use futures_core::Stream; +use monoio::blocking::spawn_blocking; use super::MonoioFile; use crate::{ + error::monoio_join_err, fs::{FileMeta, FileSystemTag, Fs, OpenOptions}, path::{path_to_local, Path}, Error, @@ -65,7 +67,9 @@ impl Fs for MonoIoFs { let from = path_to_local(from)?; let to = path_to_local(to)?; - fs::copy(&from, &to)?; + spawn_blocking(move || fs::copy(&from, &to)) + .await + .map_err(monoio_join_err)??; Ok(()) } @@ -74,7 +78,9 @@ impl Fs for MonoIoFs { let from = path_to_local(from)?; let to = path_to_local(to)?; - fs::hard_link(&from, &to)?; + spawn_blocking(move || fs::hard_link(&from, &to)) + .await + .map_err(monoio_join_err)??; Ok(()) } diff --git a/fusio/src/impls/disk/tokio/fs.rs b/fusio/src/impls/disk/tokio/fs.rs index e5f0b73..2f470d4 100644 --- a/fusio/src/impls/disk/tokio/fs.rs +++ b/fusio/src/impls/disk/tokio/fs.rs @@ -27,7 +27,7 @@ impl Fs for TokioFs { let file = tokio::fs::OpenOptions::new() .read(options.read) - .append(options.write) + .write(options.write) .create(options.create) .open(&local_path) .await?;