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
+14
View File
@@ -6,7 +6,9 @@
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
import 'navigator.locks';
import crypto from 'crypto';
import { inspect } from 'util';
import {
KeyCodes,
Modifiers,
@@ -76,3 +78,15 @@ document.addEventListener('keyup', addWhichToKeyboardEvent);
Object.defineProperty(global.self, 'crypto', {
value: crypto.webcrypto,
});
// https://github.com/facebook/jest/issues/11698
function fail(reason: unknown): never {
if (typeof reason === 'string') {
throw new Error(reason);
}
throw new Error(inspect(reason));
}
if (global.fail === undefined) {
global.fail = fail;
}