From 88638fdb8893c7899cb572653d1a7b1effda449d Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Wed, 10 Mar 2021 13:45:27 +0000 Subject: [PATCH 1/4] Add remove() to spec --- index.bs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/index.bs b/index.bs index 823a94b..6968a7a 100644 --- a/index.bs +++ b/index.bs @@ -262,6 +262,8 @@ interface FileSystemHandle { readonly attribute FileSystemHandleKind kind; readonly attribute USVString name; + Promise remove(); + Promise isSameEntry(FileSystemHandle other); Promise queryPermission(optional FileSystemHandlePermissionDescriptor descriptor = {}); @@ -315,6 +317,48 @@ and return {{FileSystemHandleKind/"directory"}} otherwise. The name attribute must return the [=entry/name=] of the associated [=FileSystemHandle/entry=]. +### The {{FileSystemHandle/remove()}} method ### {#api-filesystemhandle-remove} + +
+ : await |handle| . {{FileSystemHandle/remove()|remove}}() + :: 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. +
+ +
+The remove() 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 [=this=]'s [=FileSystemHandle/entry=]. + 1. Let |permissionStatus| be the result of [=requesting file system permission=] + given [=this=] 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 |handle| from the underlying file system. + 1. If |handle| is a [=directory entry=]: + 1. If |handle|'s path does not exists, [=/reject=] |result| with a + {{NotFoundError}} and abort + 1. If |handle|'s path is not a directory, [=/reject=] |result| with a + {{NotADirectoryError}} and abort + 1. If |handle| is not an empty directory, [=/reject=] |result| with a + {{NotEmptyError}} and abort + + 1. If |handle| is a [=file entry=]: + 1. If |handle|'s path does not exists, [=/reject=] |result| with a + {{NotFoundError}} and abort + 1. If |handle|'s path is not a file, [=/reject=] |result| with a + {{NotAFileError}} and abort + + 1. [=/Resolve=] |result| with `undefined`. + +1. Return |result|. + ### The {{FileSystemHandle/isSameEntry()}} method ### {#api-filesystemhandle-issameentry}
From 8bf2b586834eadf0d8274f0705d2b01cef8b246f Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Fri, 12 Mar 2021 14:24:42 +0000 Subject: [PATCH 2/4] Fix bs error --- index.bs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/index.bs b/index.bs index 6968a7a..08b6421 100644 --- a/index.bs +++ b/index.bs @@ -340,25 +340,27 @@ these steps: 1. If |permissionStatus| is not {{PermissionState/"granted"}}, [=/reject=] |result| with a {{NotAllowedError}} and abort. - 1. Attempt to remove |handle| from the underlying file system. - 1. If |handle| is a [=directory entry=]: - 1. If |handle|'s path does not exists, [=/reject=] |result| with a + 1. Attempt to remove |entry| from the underlying file system. + 1. If |entry| is a [=directory entry=]: + 1. If |entry|'s path does not exists, [=/reject=] |result| with a {{NotFoundError}} and abort - 1. If |handle|'s path is not a directory, [=/reject=] |result| with a + 1. If |entry|'s path is not a directory, [=/reject=] |result| with a {{NotADirectoryError}} and abort - 1. If |handle| is not an empty directory, [=/reject=] |result| with a + 1. If |entry| is not an empty directory, [=/reject=] |result| with a {{NotEmptyError}} and abort - 1. If |handle| is a [=file entry=]: - 1. If |handle|'s path does not exists, [=/reject=] |result| with a + 1. If |entry| is a [=file entry=]: + 1. If |entry|'s path does not exists, [=/reject=] |result| with a {{NotFoundError}} and abort - 1. If |handle|'s path is not a file, [=/reject=] |result| with a + 1. If |entry|'s path is not a file, [=/reject=] |result| with a {{NotAFileError}} and abort 1. [=/Resolve=] |result| with `undefined`. 1. Return |result|. +
+ ### The {{FileSystemHandle/isSameEntry()}} method ### {#api-filesystemhandle-issameentry}
From 9858a15107ce9c3f42fec28449c35053008a7cbe Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Tue, 8 Jun 2021 14:56:14 +0000 Subject: [PATCH 3/4] update removeEntry error descriptions --- index.bs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/index.bs b/index.bs index 08b6421..62a8b1e 100644 --- a/index.bs +++ b/index.bs @@ -828,14 +828,24 @@ 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 exists, [=/reject=] |result| with a + {{NotFoundError}} and abort + 1. If |child|'s path is not a directory, [=/reject=] |result| with a + {{NotADirectoryError}} and abort + 1. If |child| is not an empty directory, [=/reject=] |result| with a + {{NotEmptyError}} and abort + 1. If |child| is a [=file entry=]: + 1. If |child|'s path does not exists, [=/reject=] |result| with a + {{NotFoundError}} and abort + 1. If |child|'s path is not a file, [=/reject=] |result| with a + {{NotAFileError}} 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|. From 9429f48cbcaa0785b40615de6f39383b1a72a87f Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Tue, 8 Jun 2021 15:19:46 +0000 Subject: [PATCH 4/4] use DOMExceptions + add recursive option --- index.bs | 62 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/index.bs b/index.bs index 62a8b1e..6a368a2 100644 --- a/index.bs +++ b/index.bs @@ -262,7 +262,7 @@ interface FileSystemHandle { readonly attribute FileSystemHandleKind kind; readonly attribute USVString name; - Promise remove(); + Promise remove(optional FileSystemRemoveOptions options = {}); Promise isSameEntry(FileSystemHandle other); @@ -321,15 +321,26 @@ associated [=FileSystemHandle/entry=].
: 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. + + 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.
-The remove() method, when invoked, must run -these steps: +The remove(|options|) method, +when invoked, must run these steps: 1. Let |result| be [=a new promise=]. 1. Run the following steps [=in parallel=]: @@ -342,18 +353,21 @@ these steps: 1. Attempt to remove |entry| from the underlying file system. 1. If |entry| is a [=directory entry=]: - 1. If |entry|'s path does not exists, [=/reject=] |result| with a - {{NotFoundError}} and abort - 1. If |entry|'s path is not a directory, [=/reject=] |result| with a - {{NotADirectoryError}} and abort - 1. If |entry| is not an empty directory, [=/reject=] |result| with a - {{NotEmptyError}} and abort - + 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 exists, [=/reject=] |result| with a - {{NotFoundError}} and abort - 1. If |entry|'s path is not a file, [=/reject=] |result| with a - {{NotAFileError}} and abort + 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`. @@ -802,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.
@@ -830,17 +843,16 @@ these steps: 1. [=set/Remove=] |child| from |entry|'s [=directory entry/children=]. 1. If |child| is a [=directory entry=]: - 1. If |child|'s path does not exists, [=/reject=] |result| with a - {{NotFoundError}} and abort - 1. If |child|'s path is not a directory, [=/reject=] |result| with a - {{NotADirectoryError}} and abort - 1. If |child| is not an empty directory, [=/reject=] |result| with a - {{NotEmptyError}} and abort + 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 exists, [=/reject=] |result| with a - {{NotFoundError}} and abort - 1. If |child|'s path is not a file, [=/reject=] |result| with a - {{NotAFileError}} and abort + 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