fileStorage: implement file locks

This breaks down reading and writing into low-level and high level sagas.

Opening now takes a lock on the file so that it can only have one writer
or have multiple readers. The low-level read and write sagas use the
file descriptor to determine if the file is still open before actually
performing the action.

Since we are using the web locks api, these locks should work across
browser tabs/windows.

The high-level read/write sagas perform the low-level open, read/write,
close operations in a single call.

The high-level delete and rename sagas are also updated to take locks
on the files while performing the respective operations and will fail
if the file is already being used somewhere else.
This commit is contained in:
David Lechner
2022-04-04 15:24:08 -05:00
parent 7ef08122e8
commit b9dbaaa5cb
12 changed files with 1278 additions and 420 deletions
+23
View File
@@ -2123,6 +2123,7 @@ __metadata:
"@types/redux-logger": ^3.0.9
"@types/semver": ^7.3.9
"@types/web-bluetooth": ^0.0.13
"@types/web-locks-api": ^0.0.2
"@types/wicg-file-system-access": ^2020.9.5
"@types/zen-push": ^0.1.1
"@typescript-eslint/eslint-plugin": ^4.33.0
@@ -2149,6 +2150,7 @@ __metadata:
monaco-editor-webpack-plugin: ^6.0.0
monaco-themes: ^0.4.0
mq-polyfill: 1.1.8
navigator.locks: 0.8.1
node-sass: ^6.0.1
prettier: ^2.5.1
prop-types: ^15.8.1
@@ -2995,6 +2997,13 @@ __metadata:
languageName: node
linkType: hard
"@types/web-locks-api@npm:^0.0.2":
version: 0.0.2
resolution: "@types/web-locks-api@npm:0.0.2"
checksum: 36d8e6378f4b48143fb8ac829ebd0f071782b0a2f7db98babddfbe05a82d8332a123c88599100aceebbbb2cdf512e67ed3f2c188f8b70f38000f9563f366f298
languageName: node
linkType: hard
"@types/webpack-sources@npm:*":
version: 3.2.0
resolution: "@types/webpack-sources@npm:3.2.0"
@@ -11400,6 +11409,20 @@ __metadata:
languageName: node
linkType: hard
"navigator.locks@npm:0.8.1":
version: 0.8.1
resolution: "navigator.locks@npm:0.8.1"
checksum: 15438f3500839f91fb9fb516e35436263847182a9bf593581a5aa0f50f744b0b62957d5cf54556f733692318dd9f774ca99a40e7babe7fef2b436b8ef82fb9ca
languageName: node
linkType: hard
"navigator.locks@patch:navigator.locks@npm:0.8.1#.yarn/patches/navigator.locks-npm-0.8.1-e8530a2d4f.patch::locator=%40pybricks%2Fpybricks-code%40workspace%3A.":
version: 0.8.1
resolution: "navigator.locks@patch:navigator.locks@npm%3A0.8.1#.yarn/patches/navigator.locks-npm-0.8.1-e8530a2d4f.patch::version=0.8.1&hash=cb7184&locator=%40pybricks%2Fpybricks-code%40workspace%3A."
checksum: a4ce9fa068d07874234f11849dccc4bc265ce9baa468aea29a3734bc672be893cd6e9d1c91320b898fbe011d0c3ce8d55fb7af8ed4295f9d67feda65697f2bbe
languageName: node
linkType: hard
"negotiator@npm:0.6.3, negotiator@npm:^0.6.3":
version: 0.6.3
resolution: "negotiator@npm:0.6.3"