Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FileSystemHandle::remove() method #283

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 72 additions & 4 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ interface FileSystemHandle {
readonly attribute FileSystemHandleKind kind;
readonly attribute USVString name;

Promise<void> remove(optional FileSystemRemoveOptions options = {});

Promise<boolean> isSameEntry(FileSystemHandle other);

Promise<PermissionState> queryPermission(optional FileSystemHandlePermissionDescriptor descriptor = {});
Expand Down Expand Up @@ -315,6 +317,64 @@ and return {{FileSystemHandleKind/"directory"}} otherwise.
The <dfn attribute for=FileSystemHandle>name</dfn> attribute must return the [=entry/name=] of the
associated [=FileSystemHandle/entry=].

### The {{FileSystemHandle/remove()}} method ### {#api-filesystemhandle-remove}

<div class="note domintro">
: await |handle| . {{FileSystemHandle/remove()|remove}}()
: await |handle| . {{FileSystemHandle/remove()|remove}}({ {{FileSystemRemoveOptions/recursive}}: false })
:: Attempts to remove the entry represented by |handle| from the underlying file system.

For files or directories with multiple hardlinks or symlinks, the entry which is deleted
is the entry corresponding to the path which was used to obtain the handle.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pwnall This text was snagged from your comment here. Let me know if this needs more elaboration #214 (comment)


Attempting to delete a file or directory that does not exist is considered success,
while attempting to delete a non-empty directory will result in a promise rejection.

: await |handle| . {{FileSystemHandle/remove()|remove}}({ {{FileSystemRemoveOptions/recursive}}: true })
:: Attempts to remove the entry represented by |handle| from the underlying file system.

If the entry is a directory, its contents will also be deleted recursively.

Attempting to delete a file or directory that does not exist is considered success.
</div>

<div algorithm>
The <dfn method for=FileSystemHandle>remove(|options|)</dfn> method,
when invoked, must run these steps:

1. Let |result| be [=a new promise=].
1. Run the following steps [=in parallel=]:
1. Let |entry| be <b>[=this=]</b>'s [=FileSystemHandle/entry=].
1. Let |permissionStatus| be the result of [=requesting file system permission=]
given <b>[=this=]</b> and {{"readwrite"}}.
If that throws an exception, [=reject=] |result| with that exception and abort.
1. If |permissionStatus| is not {{PermissionState/"granted"}},
[=/reject=] |result| with a {{NotAllowedError}} and abort.

1. Attempt to remove |entry| from the underlying file system.
1. If |entry| is a [=directory entry=]:
1. If |entry|'s path does not exist:
1. [=/Reject=] |result| with a {{NotFoundError}} and abort.
1. If |entry|'s path is not a directory:
1. [=/Reject=] |result| with a {{TypeMismatchError}} and abort.
1. If |entry| is not an empty directory and |options|.{{FileSystemRemoveOptions/recursive}} is `false`:
1. [=/Reject=] |result| with an {{InvalidModificationError}} and abort.
1. If |entry| is a [=file entry=]:
1. If |entry|'s path does not exist:
1. [=/Reject=] |result| with a {{NotFoundError}} and abort.
1. If |entry|'s path is not a file:
1. [=/Reject=] |result| with a {{TypeMismatchError}} and abort.

Note: If {{FileSystemRemoveOptions/recursive}} is `true`, the removal can fail
non-atomically. Some files or directories might have been removed while other files
or directories still exist.

1. [=/Resolve=] |result| with `undefined`.

1. Return |result|.

</div>

### The {{FileSystemHandle/isSameEntry()}} method ### {#api-filesystemhandle-issameentry}

<div class="note domintro">
Expand Down Expand Up @@ -756,7 +816,6 @@ invoked, must run these steps:
: await |directoryHandle| . {{FileSystemDirectoryHandle/removeEntry()|removeEntry}}(|name|, { {{FileSystemRemoveOptions/recursive}}: true })
:: Removes the entry named |name| in the directory represented by |directoryHandle|.
If that entry is a directory, its contents will also be deleted recursively.
recursively.

Attempting to delete a file or directory that does not exist is considered success.
</div>
Expand All @@ -782,14 +841,23 @@ these steps:
1. If |child|'s [=directory entry/children=] is not [=set/is empty|empty=] and |options|.{{FileSystemRemoveOptions/recursive}} is `false`:
1. [=/Reject=] |result| with an {{InvalidModificationError}} and abort.
1. [=set/Remove=] |child| from |entry|'s [=directory entry/children=].
1. If removing |child| in the underlying file system throws an exception,
[=/reject=] |result| with that exception and abort.

1. If |child| is a [=directory entry=]:
1. If |child|'s path does not exist:
1. [=/Reject=] |result| with a {{NotFoundError}} and abort.
1. If |child|'s path is not a directory:
1. [=/Reject=] |result| with a {{TypeMismatchError}} and abort.

1. If |child| is a [=file entry=]:
1. If |child|'s path does not exist:
1. [=/Reject=] |result| with a {{NotFoundError}} and abort.
1. If |child|'s path is not a file:
1. [=/Reject=] |result| with a {{TypeMismatchError}} and abort.

Note: If {{FileSystemRemoveOptions/recursive}} is `true`, the removal can fail
non-atomically. Some files or directories might have been removed while other files
or directories still exist.

Issue(68): Better specify what possible exceptions this could throw.
1. [=/Resolve=] |result| with `undefined`.
1. [=/Reject=] |result| with a {{NotFoundError}}.
1. Return |result|.
Expand Down