Skip to content

Commit

Permalink
feat: append to a file instead of overwriting while opening for disk …
Browse files Browse the repository at this point in the history
…based file
  • Loading branch information
crwen committed Feb 5, 2025
1 parent 92fd436 commit 00371dd
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 273 deletions.
19 changes: 9 additions & 10 deletions fusio/src/impls/disk/monoio/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ impl Fs for MonoIoFs {

async fn open_options(&self, path: &Path, options: OpenOptions) -> Result<Self::File, Error> {
let local_path = path_to_local(path)?;

Ok(MonoioFile::from(
monoio::fs::OpenOptions::new()
.read(options.read)
.write(options.write)
.create(options.create)
.truncate(options.truncate)
.open(&local_path)
.await?,
))
let file = monoio::fs::OpenOptions::new()
.read(options.read)
.write(options.write)
.create(options.create)
.truncate(options.truncate)
.open(&local_path)
.await?;
let metadata = file.metadata().await.expect("monoio: get metadat failed");
Ok(MonoioFile::new(file, metadata.len()))
}

async fn create_dir_all(path: &Path) -> Result<(), Error> {
Expand Down
9 changes: 9 additions & 0 deletions fusio/src/impls/disk/monoio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ impl From<File> for MonoioFile {
}
}

impl MonoioFile {
pub(crate) fn new(file: File, pos: u64) -> Self {
Self {
file: Some(file),
pos,
}
}
}

impl Write for MonoioFile {
async fn write_all<B: IoBuf>(&mut self, buf: B) -> (Result<(), Error>, B) {
let (result, buf) = self
Expand Down
4 changes: 2 additions & 2 deletions fusio/src/impls/disk/opfs/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ impl Fs for OPFS {

cfg_if::cfg_if! {
if #[cfg(feature = "sync")] {
Ok(Self::File::new(file_handle).await?)
Ok(Self::File::new(file_handle, options).await?)
} else {
Ok(OPFSFile::new(file_handle))
Ok(OPFSFile::new(file_handle, options).await?)
}
}
}
Expand Down
Loading

0 comments on commit 00371dd

Please sign in to comment.