mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user