Skip to content

Commit

Permalink
Remove a couple of methods from Fd
Browse files Browse the repository at this point in the history
Either their signature will likely change once they are actually
implemented in one of the Fd impls or they are not strictly necessary to
exist.
  • Loading branch information
bjorn3 committed Apr 9, 2024
1 parent d224e9d commit bbdfeee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
9 changes: 0 additions & 9 deletions src/fd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
import * as wasi from "./wasi_defs.js";

export abstract class Fd {
fd_advise(offset: bigint, len: bigint, advice: number): number {
return wasi.ERRNO_SUCCESS;
}
fd_allocate(offset: bigint, len: bigint): number {
return wasi.ERRNO_NOTSUP;
}
fd_close(): number {
return 0;
}
fd_datasync(): number {
return wasi.ERRNO_NOTSUP;
}
fd_fdstat_get(): { ret: number; fdstat: wasi.Fdstat | null } {
return { ret: wasi.ERRNO_NOTSUP, fdstat: null };
}
Expand Down Expand Up @@ -120,9 +114,6 @@ export abstract class Fd {
path_rename(old_path: string, new_fd: number, new_path: string): number {
return wasi.ERRNO_NOTSUP;
}
path_symlink(old_path: string, new_path: string): number {
return wasi.ERRNO_NOTSUP;
}
path_unlink_file(path: string): number {
return wasi.ERRNO_NOTSUP;
}
Expand Down
6 changes: 1 addition & 5 deletions src/fs_opfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,8 @@ export class OpenSyncOPFSFile extends Fd {
return { ret: wasi.ERRNO_SUCCESS, nwritten: n };
}

fd_datasync(): number {
fd_sync(): number {
this.file.handle.flush();
return wasi.ERRNO_SUCCESS;
}

fd_sync(): number {
return this.fd_datasync();
}
}
11 changes: 8 additions & 3 deletions src/wasi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,15 @@ export default class WASI {

fd_advise(
fd: number,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
offset: bigint,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
len: bigint,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
advice: number,
): number {
if (self.fds[fd] != undefined) {
return self.fds[fd].fd_advise(offset, len, advice);
return wasi.ERRNO_SUCCESS;
} else {
return wasi.ERRNO_BADF;
}
Expand All @@ -212,7 +215,7 @@ export default class WASI {
},
fd_datasync(fd: number): number {
if (self.fds[fd] != undefined) {
return self.fds[fd].fd_datasync();
return self.fds[fd].fd_sync();
} else {
return wasi.ERRNO_BADF;
}
Expand Down Expand Up @@ -788,13 +791,15 @@ export default class WASI {
): number {
const buffer8 = new Uint8Array(self.inst.exports.memory.buffer);
if (self.fds[fd] != undefined) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const old_path = new TextDecoder("utf-8").decode(
buffer8.slice(old_path_ptr, old_path_ptr + old_path_len),
);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const new_path = new TextDecoder("utf-8").decode(
buffer8.slice(new_path_ptr, new_path_ptr + new_path_len),
);
return self.fds[fd].path_symlink(old_path, new_path);
return wasi.ERRNO_NOTSUP;
} else {
return wasi.ERRNO_BADF;
}
Expand Down

0 comments on commit bbdfeee

Please sign in to comment.