-
Notifications
You must be signed in to change notification settings - Fork 21
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 #9
Open
a-sully
wants to merge
2
commits into
whatwg:main
Choose a base branch
from
a-sully:remove
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,6 +332,7 @@ interface FileSystemHandle { | |
readonly attribute USVString name; | ||
|
||
Promise<boolean> isSameEntry(FileSystemHandle other); | ||
Promise<undefined> remove(optional FileSystemRemoveOptions options = {}); | ||
}; | ||
</xmp> | ||
|
||
|
@@ -416,6 +417,100 @@ The <dfn method for=FileSystemHandle>isSameEntry(|other|)</dfn> method steps are | |
|
||
</div> | ||
|
||
### The {{FileSystemHandle/remove()}} method ### {#api-filesystemhandle-remove} | ||
|
||
<div class="note domintro"> | ||
: await |handle| . {{FileSystemHandle/remove()|remove}}() | ||
: await |handle| . {{FileSystemHandle/remove()|remove}}({ {{FileSystemRemoveOptions/recursive}}: false }) | ||
:: Deletes the [=file system entry=] [=locate an entry|locatable=] by | ||
|handle|'s [=FileSystemHandle/locator=] from the underlying file system. | ||
|
||
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 }) | ||
:: Deletes the [=file system entry=] [=locate an entry|locatable=] by | ||
|handle|'s [=FileSystemHandle/locator=] from the underlying file system. | ||
If that [=file system entry=] is a [=directory entry=], | ||
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 steps are: | ||
|
||
1. Let |result| be [=a new promise=]. | ||
1. Let |locator| be [=this=]'s [=FileSystemHandle/locator=]. | ||
1. Let |global| be [=this=]'s [=relevant global object=]. | ||
1. Let |isInABucketFileSystem| be true if | ||
[=this=] [=FileSystemHandle/is in a bucket file system=]; | ||
otherwise false. | ||
1. [=Enqueue the following steps=] to the [=file system queue=]: | ||
1. Let |entry| be the result of [=locating an entry=] given |locator|. | ||
1. Let |accessResult| be the result of running |entry|'s | ||
[=file system entry/request access=] given "`readwrite`". | ||
1. If |accessResult|'s [=file system access result/permission state=] | ||
is not "{{PermissionState/granted}}", [=queue a storage task=] with | ||
|global| to [=/reject=] |result| with a {{DOMException}} of | ||
|accessResult|'s [=file system access result/error name=] and | ||
abort these steps. | ||
|
||
1. If |entry| is `null`, [=queue a storage task=] with |global| to [=/reject=] | ||
|result| with a "{{NotFoundError}}" {{DOMException}} and abort these steps. | ||
|
||
1. Let |lockResult| be the result of [=file entry/lock/take|taking a lock=] | ||
with "`exclusive`" on |entry|. | ||
|
||
a-sully marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Issue(137): Support locking directory entries. | ||
|
||
1. [=Queue a storage task=] with |global| to run these steps: | ||
1. If |lockResult| is "`failure`", [=/reject=] |result| with a | ||
"{{NoModificationAllowedError}}" {{DOMException}} and abort these steps. | ||
|
||
1. If |entry| is a [=directory entry=]: | ||
1. If |entry|'s [=directory entry/children=] [=set/is empty=] and | ||
|options|["{{FileSystemRemoveOptions/recursive}}"] is false, | ||
[=/reject=] |result| with an | ||
"{{InvalidModificationError}}" {{DOMException}} and abort these steps. | ||
|
||
1. Let |isTheRootOfABucketFileSystem| be true if | ||
|isInABucketFileSystem| is true and | ||
|entry|'s [=file system entry/parent=] is `null`; | ||
otherwise false. | ||
1. If |isTheRootOfABucketFileSystem| is true: | ||
1. [=set/For each=] |child| of |entry|'s [=directory entry/children=]: | ||
1. Attempt to remove |child| from the underlying file system. | ||
If that throws an exception, [=/reject=] |result| with | ||
that exception and abort these steps. | ||
Comment on lines
+485
to
+487
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems weird that this would happen on the main thread. |
||
1. Set |entry|'s [=directory entry/children=] to an empty [=/set=]. | ||
1. [=/Resolve=] |result| with `undefined` and abort these steps. | ||
|
||
1. If |entry|'s [=file system entry/parent=] is not `null`, | ||
[=set/remove=] |entry| from |entry|'s [=file system entry/parent=]'s | ||
[=directory entry/children=]. | ||
|
||
1. Attempt to remove |entry| from the underlying file system. | ||
If that throws an exception, [=/reject=] |result| with that exception | ||
and abort these steps. | ||
|
||
Note: If |options|["{{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(11): Better specify what possible exceptions this could throw. | ||
|
||
1. [=Enqueue the following steps=] to the [=file system queue=]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need nested file system queue steps? |
||
1. [=file entry/lock/release|Release the lock=] on |entry|. | ||
1. [=Queue a storage task=] with |global| to | ||
[=/resolve=] |result| with `undefined`. | ||
|
||
1. Return |result|. | ||
|
||
</div> | ||
|
||
## The {{FileSystemFileHandle}} interface ## {#api-filesystemfilehandle} | ||
|
||
<xmp class=idl> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: https://infra.spec.whatwg.org doesn't use markup for null.