mirror of
https://github.com/denoland/deno.git
synced 2024-12-02 17:01:14 -05:00
feat(std/wasi): implement fd_datasync (#6556)
This commit is contained in:
parent
53f8d96a1f
commit
4cde7fdc9a
3 changed files with 28 additions and 2 deletions
|
@ -15,7 +15,7 @@ This module provides an implementation of the WebAssembly System Interface
|
|||
- [ ] fd_advise
|
||||
- [ ] fd_allocate
|
||||
- [x] fd_close
|
||||
- [ ] fd_datasync
|
||||
- [x] fd_datasync
|
||||
- [x] fd_fdstat_get
|
||||
- [ ] fd_fdstat_set_flags
|
||||
- [ ] fd_fdstat_set_rights
|
||||
|
|
|
@ -492,7 +492,18 @@ export default class Module {
|
|||
},
|
||||
|
||||
fd_datasync: (fd: number): number => {
|
||||
return ERRNO_NOSYS;
|
||||
const entry = this.fds[fd];
|
||||
if (!entry) {
|
||||
return ERRNO_BADF;
|
||||
}
|
||||
|
||||
try {
|
||||
Deno.fdatasyncSync(entry.handle.rid);
|
||||
} catch (err) {
|
||||
return errno(err);
|
||||
}
|
||||
|
||||
return ERRNO_SUCCESS;
|
||||
},
|
||||
|
||||
fd_fdstat_get: (fd: number, stat_out: number): number => {
|
||||
|
|
15
std/wasi/testdata/std_fs_file_sync_data.rs
vendored
Normal file
15
std/wasi/testdata/std_fs_file_sync_data.rs
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
// { "preopens": { "/scratch": "scratch" } }
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
fn main() {
|
||||
let mut file = std::fs::File::create("/scratch/file").unwrap();
|
||||
|
||||
assert!(file.write(b"Hello").is_ok());
|
||||
assert!(file.sync_data().is_ok());
|
||||
assert_eq!(std::fs::read("/scratch/file").unwrap(), b"Hello");
|
||||
|
||||
assert!(file.write(b", world!").is_ok());
|
||||
assert!(file.sync_data().is_ok());
|
||||
assert_eq!(std::fs::read("/scratch/file").unwrap(), b"Hello, world!");
|
||||
}
|
Loading…
Reference in a new issue