1
0
Fork 0
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:
Casper Beyer 2020-06-29 22:44:08 +08:00 committed by GitHub
parent 53f8d96a1f
commit 4cde7fdc9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View file

@ -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

View file

@ -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 => {

View 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!");
}