Skip to content

Commit

Permalink
fix: fix the semantics of append writing when TokioFs::open_options (…
Browse files Browse the repository at this point in the history
…write from scratch after reopening)
  • Loading branch information
KKould committed Nov 15, 2024
1 parent fdd7348 commit ea56dba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fusio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
8 changes: 8 additions & 0 deletions fusio/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub enum Error {
Wasm {
message: String,
},
#[cfg(feature = "monoio")]
#[error("monoio JoinHandle was canceled")]
MonoIOJoinCancel,
#[error(transparent)]
Other(#[from] BoxedError),
}
Expand All @@ -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
}
10 changes: 8 additions & 2 deletions fusio/src/impls/disk/monoio/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(())
}
Expand All @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion fusio/src/impls/disk/tokio/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down

0 comments on commit ea56dba

Please sign in to comment.