mirror of
https://github.com/fluencelabs/wasmer
synced 2025-05-12 10:37:11 +00:00
implement datasync
This commit is contained in:
parent
e61c03a176
commit
2de5a5da2b
@ -7,6 +7,7 @@ use generational_arena::{Arena, Index as Inode};
|
|||||||
use hashbrown::hash_map::{Entry, HashMap};
|
use hashbrown::hash_map::{Entry, HashMap};
|
||||||
use std::{
|
use std::{
|
||||||
cell::{Cell, RefCell},
|
cell::{Cell, RefCell},
|
||||||
|
io::{self, Write},
|
||||||
ops::{Index, IndexMut},
|
ops::{Index, IndexMut},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
@ -212,6 +213,31 @@ impl WasiFs {
|
|||||||
Err(__WASI_EBADF)
|
Err(__WASI_EBADF)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn flush(&mut self, fd: __wasi_fd_t) -> Result<(), __wasi_errno_t> {
|
||||||
|
match fd {
|
||||||
|
0 => (),
|
||||||
|
1 => io::stdout().flush().map_err(|_| __WASI_EIO)?,
|
||||||
|
2 => io::stderr().flush().map_err(|_| __WASI_EIO)?,
|
||||||
|
_ => {
|
||||||
|
let fd = self.fd_map.get(&fd).ok_or(__WASI_EBADF)?;
|
||||||
|
if fd.rights & __WASI_RIGHT_FD_DATASYNC == 0 {
|
||||||
|
return Err(__WASI_EACCES);
|
||||||
|
}
|
||||||
|
|
||||||
|
let inode = &mut self.inodes[fd.inode];
|
||||||
|
|
||||||
|
match &mut inode.kind {
|
||||||
|
Kind::File { handle } => handle.flush().map_err(|_| __WASI_EIO)?,
|
||||||
|
// TODO: verify this behavior
|
||||||
|
Kind::Dir { .. } => return Err(__WASI_EISDIR),
|
||||||
|
Kind::Symlink { .. } => unimplemented!(),
|
||||||
|
Kind::Buffer { .. } => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WasiState<'a> {
|
pub struct WasiState<'a> {
|
||||||
|
@ -256,7 +256,13 @@ pub fn fd_close(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t {
|
|||||||
/// The file descriptor to sync
|
/// The file descriptor to sync
|
||||||
pub fn fd_datasync(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t {
|
pub fn fd_datasync(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t {
|
||||||
debug!("wasi::fd_datasync");
|
debug!("wasi::fd_datasync");
|
||||||
unimplemented!()
|
let state = get_wasi_state(ctx);
|
||||||
|
|
||||||
|
if let Err(e) = state.fs.flush(fd) {
|
||||||
|
e
|
||||||
|
} else {
|
||||||
|
__WASI_ESUCCESS
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### `fd_fdstat_get()`
|
/// ### `fd_fdstat_get()`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user