Skip to content

Commit

Permalink
feat(wasi): implement fd_datasync (denoland/deno#6556)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb authored and denobot committed Feb 1, 2021
1 parent a323688 commit 9e603d5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion wasi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion wasi/snapshot_preview1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
15 changes: 15 additions & 0 deletions wasi/testdata/std_fs_file_sync_data.rs
Original file line number Diff line number Diff line change
@@ -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!");
}

0 comments on commit 9e603d5

Please sign in to comment.