1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

feat(std/wasi) implement fd_filestat_set_size (#6558)

This commit is contained in:
Casper Beyer 2020-06-30 02:36:22 +08:00 committed by GitHub
parent 4cde7fdc9a
commit 3c5459d849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View file

@ -20,7 +20,7 @@ This module provides an implementation of the WebAssembly System Interface
- [ ] fd_fdstat_set_flags
- [ ] fd_fdstat_set_rights
- [x] fd_filestat_get
- [ ] fd_filestat_set_size
- [x] fd_filestat_set_size
- [x] fd_filestat_set_times
- [x] fd_pread
- [x] fd_prestat_get

View file

@ -607,7 +607,18 @@ export default class Module {
},
fd_filestat_set_size: (fd: number, size: bigint): number => {
return ERRNO_NOSYS;
const entry = this.fds[fd];
if (!entry) {
return ERRNO_BADF;
}
try {
Deno.ftruncateSync(entry.handle.rid, Number(size));
} catch (err) {
return errno(err);
}
return ERRNO_SUCCESS;
},
fd_filestat_set_times: (

View file

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