Skip to content

Commit

Permalink
return proper ERRNOs in OpenDirectory.path_open (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansemjo authored Sep 5, 2023
1 parent 9674246 commit 79d4e12
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/fs_fd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,33 +240,39 @@ export class OpenDirectory extends Fd {
let entry = this.dir.get_entry_for_path(path);
if (entry == null) {
if ((oflags & wasi.OFLAGS_CREAT) == wasi.OFLAGS_CREAT) {
// doesn't exist, but shall be created
entry = this.dir.create_entry_for_path(path, (oflags & wasi.OFLAGS_DIRECTORY) == wasi.OFLAGS_DIRECTORY);
} else {
return { ret: -1, fd_obj: null };
// doesn't exist, no such file
return { ret: wasi.ERRNO_NOENT, fd_obj: null };
}
} else if ((oflags & wasi.OFLAGS_EXCL) == wasi.OFLAGS_EXCL) {
return { ret: -1, fd_obj: null };
// was supposed to be created exclusively, but exists already
return { ret: wasi.ERRNO_EXIST, fd_obj: null };
}
if (
(oflags & wasi.OFLAGS_DIRECTORY) == wasi.OFLAGS_DIRECTORY &&
entry.stat().filetype != wasi.FILETYPE_DIRECTORY
) {
return { ret: -1, fd_obj: null };
// file is actually a directory
return { ret: wasi.ERRNO_ISDIR, fd_obj: null };
}
if (entry.readonly &&
(fs_rights_base & BigInt(wasi.RIGHTS_FD_WRITE)) == BigInt(wasi.RIGHTS_FD_WRITE)
) {
// no write permission to file
return { ret: wasi.ERRNO_PERM, fd_obj: null };
}
if (
(!(entry instanceof Directory)) &&
(oflags & wasi.OFLAGS_TRUNC) == wasi.OFLAGS_TRUNC
) {
// truncate existing file first
let ret = entry.truncate();
if (ret != wasi.ERRNO_SUCCESS)
return { ret, fd_obj: null };
}
return { ret: 0, fd_obj: entry.open(fd_flags) };
return { ret: wasi.ERRNO_SUCCESS, fd_obj: entry.open(fd_flags) };
}

path_create_directory(path: string): number {
Expand Down

0 comments on commit 79d4e12

Please sign in to comment.