Skip to content

feature request: Implement both path_remove_directory and path_unlink_file #49

@HarikrishnanBalagopal

Description

@HarikrishnanBalagopal

Feature Request

We are implementing 2 of the syscalls that deal with removing files and empty directories.

path_remove_directory(path): number {
return -1;
}

browser_wasi_shim/src/fd.ts

Lines 108 to 110 in 7349f7d

path_unlink_file(path): number {
return -1;
}

https://wasix.org/docs/api-reference/wasi/path_unlink_file
https://wasix.org/docs/api-reference/wasi/path_remove_directory

Status

We have implemented both and it seems to work for empty file and empty directory.
The code is based on https://github.com/bjorn3/browser_wasi_shim/pull/42/files#diff-177a21b9f40c72ea679cf8658d14ed0d9702afcea694e92e0936f11ab182d2a3R331-R333
with some additional checks.

Challenges

  • Fails on a directory that is not empty. In Golang with https://pkg.go.dev/os#RemoveAll it uses a recursive algorithm with unlinkat to unlink the files and remove the empty directories. This goes into an infinite loop.
  • The WASI spec requires that we check file and directory permissions/rights before removing/unlinking but the rights base isn't stored anywhere? We couldn't find many examples of checking rights
    export const RIGHTS_PATH_UNLINK_FILE = 1 << 26;

    other than
    (fs_rights_base & BigInt(wasi.RIGHTS_FD_WRITE)) ==
    BigInt(wasi.RIGHTS_FD_WRITE)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions