1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

feat(std/wasi): implement fd_sync (#6560)

This commit is contained in:
Casper Beyer 2020-06-30 05:45:39 +08:00 committed by GitHub
parent a19d6a2613
commit cb16439e85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View file

@ -30,7 +30,7 @@ This module provides an implementation of the WebAssembly System Interface
- [ ] fd_readdir
- [x] fd_renumber
- [x] fd_seek
- [ ] fd_sync
- [x] fd_sync
- [x] fd_tell
- [x] fd_write
- [x] path_create_directory

View file

@ -842,7 +842,18 @@ export default class Module {
},
fd_sync: (fd: number): number => {
return ERRNO_NOSYS;
const entry = this.fds[fd];
if (!entry) {
return ERRNO_BADF;
}
try {
Deno.fsyncSync(entry.handle.rid);
} catch (err) {
return errno(err);
}
return ERRNO_SUCCESS;
},
fd_tell: (fd: number, offset_out: number): number => {

View file

@ -0,0 +1,15 @@
// { "preopens": { "/scratch": "scratch" } }
fn main() {
let file = std::fs::File::create("/scratch/file").unwrap();
assert!(file.set_len(5).is_ok());
assert!(file.sync_all().is_ok());
let metadata = std::fs::metadata("/scratch/file").unwrap();
assert_eq!(metadata.len(), 5);
assert!(file.set_len(25).is_ok());
assert!(file.sync_all().is_ok());
let metadata = std::fs::metadata("/scratch/file").unwrap();
assert_eq!(metadata.len(), 25);
}