Skip to content

Commit

Permalink
Support locking of directory entries
Browse files Browse the repository at this point in the history
Moves the locking algorithm from file entry to file system entry.

Fixes whatwg#137
  • Loading branch information
Nathan Memmott committed Jul 12, 2023
1 parent fad217a commit 9c645b0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ result of [=starting a new parallel queue=]. This queue is to be used for all
file sytem operations.

<div algorithm>
To <dfn for="file system entry/lock">take</dfn> a [=file system entry/lock=] with a |value| of
To <dfn for="file system entry/lock">take a lock</dfn> with a |value| of
"`exclusive`" or "`shared`" on a given [=/file system entry=] |entry|:

1. Let |lock| be the |entry|'s [=file system entry/lock=].
1. Let |count| be the |entry|'s [=file system entry/shared lock count=].
1. Let |hasDescendantLock| be the result of [=file system entry/lock/checking for a descendant lock=] on |entry|.
1. If |hasDescendantLock| is true:
1. Let |descendantLockStatus| be the result of [=file system entry/lock/checking for a descendant lock=] on |entry|.
1. If |descendantLockStatus| is "`taken`":
1. Return "`failure`".
1. If |value| is "`exclusive`":
1. If |lock| is "`open`":
Expand All @@ -162,13 +162,13 @@ To <dfn for="file system entry/lock">check for a descendant lock</dfn> on a give

1. Let |lock| be the |entry|'s [=file system entry/lock=].
1. If |lock| is not "`open`":
1. Return true.
1. Return "`taken`".
1. If |entry| is a [=directory entry=]:
1. [=set/For each=] |child| of |entry|'s [=directory entry/children=]:
1. Let |hasDescendantLock| be the result of [=file system entry/lock/checking for a descendant lock=] on |child|.
1. If |hasDescendantLock| is true:
1. Return true.
1. Return false.
1. Let |descendantLockStatus| be the result of [=file system entry/lock/checking for a descendant lock=] on |child|.
1. If |descendantLockStatus| is "`taken`":
1. Return "`taken`".
1. Return "`open`".

Note: These steps have to be run on the [=file system queue=].

Expand Down Expand Up @@ -558,7 +558,7 @@ The <dfn method for=FileSystemFileHandle>getFile()</dfn> method steps are:
the temporary file starts out empty,
otherwise the existing file is first copied to this temporary file.

Creating a {{FileSystemWritableFileStream}} [=file system entry/lock/take|takes a shared lock=] on the
Creating a {{FileSystemWritableFileStream}} [=file system entry/lock/take a lock|takes a shared lock=] on the
[=file entry=] [=locate an entry|locatable=] with |fileHandle|'s [=FileSystemHandle/locator=].
This prevents the creation of {{FileSystemSyncAccessHandle|FileSystemSyncAccessHandles}}
for the entry, until the stream is closed.
Expand Down Expand Up @@ -595,7 +595,7 @@ The <dfn method for=FileSystemFileHandle>createWritable(|options|)</dfn> method
|result| with a "{{NotFoundError}}" {{DOMException}} and abort these steps.
1. [=Assert=]: |entry| is a [=file entry=].

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

1. [=Queue a storage task=] with |global| to run these steps:
Expand Down Expand Up @@ -623,7 +623,7 @@ The <dfn method for=FileSystemFileHandle>createWritable(|options|)</dfn> method
[=file entry=] [=locate an entry|locatable=] by |fileHandle|'s [=FileSystemHandle/locator=].
To ensure the changes are reflected in this file, the handle can be flushed.

Creating a {{FileSystemSyncAccessHandle}} [=file system entry/lock/take|takes an exclusive lock=] on the
Creating a {{FileSystemSyncAccessHandle}} [=file system entry/lock/take a lock|takes an exclusive lock=] on the
[=file entry=] [=locate an entry|locatable=] with |fileHandle|'s [=FileSystemHandle/locator=].
This prevents the creation of further {{FileSystemSyncAccessHandle|FileSystemSyncAccessHandles}}
or {{FileSystemWritableFileStream|FileSystemWritableFileStreams}}
Expand Down Expand Up @@ -665,7 +665,7 @@ The <dfn method for=FileSystemFileHandle>createSyncAccessHandle()</dfn> method s
|result| with a "{{NotFoundError}}" {{DOMException}} and abort these steps.
1. [=Assert=]: |entry| is a [=file entry=].

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

1. [=Queue a storage task=] with |global| to run these steps:
Expand Down

0 comments on commit 9c645b0

Please sign in to comment.