mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
feat(std/wasi): implement fd_sync (#6560)
This commit is contained in:
parent
a19d6a2613
commit
cb16439e85
3 changed files with 28 additions and 2 deletions
|
@ -30,7 +30,7 @@ This module provides an implementation of the WebAssembly System Interface
|
||||||
- [ ] fd_readdir
|
- [ ] fd_readdir
|
||||||
- [x] fd_renumber
|
- [x] fd_renumber
|
||||||
- [x] fd_seek
|
- [x] fd_seek
|
||||||
- [ ] fd_sync
|
- [x] fd_sync
|
||||||
- [x] fd_tell
|
- [x] fd_tell
|
||||||
- [x] fd_write
|
- [x] fd_write
|
||||||
- [x] path_create_directory
|
- [x] path_create_directory
|
||||||
|
|
|
@ -842,7 +842,18 @@ export default class Module {
|
||||||
},
|
},
|
||||||
|
|
||||||
fd_sync: (fd: number): number => {
|
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 => {
|
fd_tell: (fd: number, offset_out: number): number => {
|
||||||
|
|
15
std/wasi/testdata/std_fs_file_sync_all.rs
vendored
Normal file
15
std/wasi/testdata/std_fs_file_sync_all.rs
vendored
Normal 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);
|
||||||
|
}
|
Loading…
Reference in a new issue