Skip to content

Commit

Permalink
Specify "origin private file system"-ness on a FileSystemHandle
Browse files Browse the repository at this point in the history
Gives a FileSystemHandle an "is in an origin private file system" predicate which checks for the empty string in its path

Better defining the OPFS itself (in terms of the Storage spec) is left to a follow-up

Fixes #103
  • Loading branch information
a-sully committed Jun 14, 2023
1 parent 2a7b613 commit b2644f0
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Each [=/file system locator=] has an associated <dfn export for="file system loc
a <dfn export for="file system locator" id=locator-kind>kind</dfn> (a {{FileSystemHandleKind}}), and
a <dfn export for="file system locator" id=locator-root>root</dfn> (a [=file system root=]).

Issue(103): Consider giving each locator a Storage Bucket.
Issue(109): Consider giving each locator a [=storage bucket=].

A <dfn export>file locator</dfn> is a [=/file system locator=] whose
[=file system locator/kind=] is {{FileSystemHandleKind/"file"}}.
Expand Down Expand Up @@ -341,6 +341,20 @@ A {{FileSystemHandle}} object is associated with a <dfn for=FileSystemHandle exp
Note: Multiple {{FileSystemHandle}} objects can have
[=the same locator as|the same=] [=/file system locator=].

A {{FileSystemHandle}}
<dfn for=FileSystemHandle export>is in an origin private file system</dfn>
if the first [=list/item=] of its [=FileSystemHandle/locator=]'s
[=file system locator/path=] is the empty string.

Note: This is a bit magical, but it works since only the root directory of an
[=origin private file system=] can have a [=file system locator/path=] which
[=list/contains=] an empty string. See {{StorageManager/getDirectory()}}.
All other [=list/item=]s of a [=file system locator/path=] will be a
[=valid file name=].

Issue(109): Consider improving this situation by giving each locator a
[=storage bucket=].

<div algorithm="serialization steps">
{{FileSystemHandle}} objects are [=serializable objects=].

Expand Down Expand Up @@ -594,8 +608,8 @@ The <dfn method for=FileSystemFileHandle>createWritable(|options|)</dfn> method
The returned {{FileSystemSyncAccessHandle}} offers synchronous methods. This allows for higher performance
on contexts where asynchronous operations come with high overhead, e.g., WebAssembly.

For the time being, this method will only succeed when the |fileHandle| belongs to the
[=origin private file system=].
For the time being, this method will only succeed when the |fileHandle|
[=FileSystemHandle/is in an origin private file system=].
</div>

<div algorithm>
Expand All @@ -605,6 +619,9 @@ The <dfn method for=FileSystemFileHandle>createSyncAccessHandle()</dfn> method s
1. Let |locator| be [=this=]'s [=FileSystemHandle/locator=].
1. Let |realm| be [=this=]'s [=relevant Realm=].
1. Let |global| be [=this=]'s [=relevant global object=].
1. Let |isInAnOriginPrivateFileSystem| be true if
[=this=] [=FileSystemHandle/is in an origin private 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
Expand All @@ -615,15 +632,15 @@ The <dfn method for=FileSystemFileHandle>createSyncAccessHandle()</dfn> method s
|accessResult|'s [=file system access result/error name=] and
abort these steps.

1. If |isInAnOriginPrivateFileSystem| is false,
[=queue a storage task=] with |global| to
[=/reject=] |result| with an "{{InvalidStateError}}" {{DOMException}} 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. [=Assert=]: |entry| is a [=file entry=].

1. If |entry| does not represent a [=/file system entry=] in an
[=origin private file system=], [=queue a storage task=] with |global| to
[=/reject=] |result| with an "{{InvalidStateError}}" {{DOMException}} and
abort these steps.

1. Let |lockResult| be the result of [=file entry/lock/take|taking a lock=]
with "`exclusive`" on |entry|.

Expand Down Expand Up @@ -1653,7 +1670,7 @@ partial interface StorageManager {

<div class="note domintro">
: |directoryHandle| = await navigator . storage . {{StorageManager/getDirectory()}}
:: Returns the root directory of the origin private file system.
:: Returns the root directory of the [=origin private file system=].
</div>

<div algorithm>
Expand Down

0 comments on commit b2644f0

Please sign in to comment.