@waffle-os/runtime 0.0.147 → 0.0.148
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/filesystem-backend.ts +26 -5
- package/browser/fs-worker.ts +5 -2
- package/browser/shared-fs.ts +93 -10
- package/core/filesystem.ts +2 -0
- package/dist/browser/filesystem-backend.js +19 -2
- package/dist/browser/fs-worker.js +7 -2
- package/dist/browser/shared-fs.js +77 -8
- package/dist/fs/client.js +82 -21
- package/dist/fs/directory-pages.js +22 -7
- package/dist/fs/guest-watch.js +9 -3
- package/dist/fs/idle-database.js +1 -1
- package/dist/fs/idle-owner.js +35 -4
- package/dist/fs/indexeddb.js +322 -63
- package/dist/fs/memory.js +18 -9
- package/dist/fs/multitab-backend.js +5065 -0
- package/dist/fs/multitab-protocol.js +301 -0
- package/dist/fs/opfs.js +21 -0
- package/dist/fs/persistent.js +70 -1
- package/dist/fs/protocol.js +1 -1
- package/dist/fs/service.js +266 -86
- package/dist/fs/shared.js +45 -0
- package/dist/fs/vfs.js +26 -8
- package/dist/fs/watch-ring.js +7 -3
- package/dist/proc/command-stdio.js +56 -1
- package/dist/runtime.js +4 -2
- package/dist/tooling/program/program-transformer.json +1 -1
- package/fs/backend.ts +36 -0
- package/fs/client.ts +81 -19
- package/fs/directory-pages.ts +40 -6
- package/fs/guest-watch.ts +8 -3
- package/fs/idle-database.ts +1 -0
- package/fs/idle-owner.ts +48 -12
- package/fs/indexeddb.ts +396 -78
- package/fs/memory.ts +33 -9
- package/fs/multitab-backend.ts +6870 -0
- package/fs/multitab-protocol.ts +655 -0
- package/fs/opfs.ts +21 -0
- package/fs/persistent.ts +70 -1
- package/fs/protocol.ts +1 -1
- package/fs/service.ts +314 -109
- package/fs/shared.ts +45 -0
- package/fs/storage.ts +3 -0
- package/fs/vfs.ts +44 -15
- package/fs/watch-ring.ts +5 -2
- package/package.json +1 -1
- package/proc/command-stdio.ts +72 -2
- package/runtime.ts +12 -3
- package/tooling/program/program-transformer.json +1 -1
package/dist/fs/client.js
CHANGED
|
@@ -340,7 +340,7 @@ function preparationFailed(completion) {
|
|
|
340
340
|
const state = completion?.cells[0];
|
|
341
341
|
return state === State.Failed || state === State.Cancelled;
|
|
342
342
|
}
|
|
343
|
-
function clientWatches(cells, revoked, call) {
|
|
343
|
+
function clientWatches(cells, revoked, remote, call) {
|
|
344
344
|
return {
|
|
345
345
|
get cells() {
|
|
346
346
|
return cells();
|
|
@@ -348,6 +348,9 @@ function clientWatches(cells, revoked, call) {
|
|
|
348
348
|
get revoked() {
|
|
349
349
|
return revoked();
|
|
350
350
|
},
|
|
351
|
+
get remote() {
|
|
352
|
+
return remote();
|
|
353
|
+
},
|
|
351
354
|
open: (handle, recursive) => call("watchOpen", [handle, recursive]),
|
|
352
355
|
read: (id) => call("watchRead", [id]),
|
|
353
356
|
close: (id) => {
|
|
@@ -421,7 +424,7 @@ export class FilesystemClient {
|
|
|
421
424
|
this.resident = new ResidentAttachment(connection.residentPublication, this.revoked);
|
|
422
425
|
this.section = new FilesystemTransportSection(connection, this.requests.memory, this.revoked);
|
|
423
426
|
this.shared = new SharedFilesystemState(connection.shared, connection.maxBytes, connection.owner, connection.segments, this.section, connection.publication?.buffers);
|
|
424
|
-
this.watches = clientWatches(() => this.shared.watch.cells, this.revoked, (operation, args) => this.call(operation, args));
|
|
427
|
+
this.watches = clientWatches(() => this.shared.watch.cells, this.revoked, () => this.shared.isDirectDisabled(), (operation, args) => this.call(operation, args));
|
|
425
428
|
connection.port.onmessage = ({ data }) => {
|
|
426
429
|
if (data.segment)
|
|
427
430
|
this.attachSegment(data.segment, data.buffer);
|
|
@@ -774,7 +777,7 @@ export class FilesystemClient {
|
|
|
774
777
|
return count;
|
|
775
778
|
if (atomicsCompareExchange(this.capabilities, key + 1, count, count - 1) !== count)
|
|
776
779
|
continue;
|
|
777
|
-
if (count === 1 && !this.revoked() && (!this.resident && this.shared.isUnlinked(atomicsLoad(this.capabilities, key)) || atomicsLoad(this.capabilities, 0) > TRANSIENT_HANDLES))
|
|
780
|
+
if (count === 1 && !this.revoked() && (this.shared.isDirectDisabled() || !this.resident && this.shared.isUnlinked(atomicsLoad(this.capabilities, key)) || atomicsLoad(this.capabilities, 0) > TRANSIENT_HANDLES))
|
|
778
781
|
this.connection.port.postMessage({ trim: true });
|
|
779
782
|
return count - 1;
|
|
780
783
|
}
|
|
@@ -847,6 +850,8 @@ export class FilesystemClient {
|
|
|
847
850
|
}
|
|
848
851
|
}
|
|
849
852
|
directSlot(handle) {
|
|
853
|
+
if (this.shared.isDirectDisabled())
|
|
854
|
+
return 0;
|
|
850
855
|
const cached = mapGet(this.fileSlots, handle);
|
|
851
856
|
if (cached !== undefined)
|
|
852
857
|
return cached;
|
|
@@ -1056,6 +1061,8 @@ export class FilesystemClient {
|
|
|
1056
1061
|
}
|
|
1057
1062
|
}
|
|
1058
1063
|
tryRead(handle, chunks, offset) {
|
|
1064
|
+
if (this.shared.isDirectDisabled())
|
|
1065
|
+
return -58;
|
|
1059
1066
|
if (this.resident)
|
|
1060
1067
|
return this.residentIO(() => this.resident?.client?.tryRead(handle, chunks, offset) ?? -6);
|
|
1061
1068
|
if (!(offset >= 0))
|
|
@@ -1083,6 +1090,8 @@ export class FilesystemClient {
|
|
|
1083
1090
|
}
|
|
1084
1091
|
}
|
|
1085
1092
|
tryWrite(handle, chunks, offset) {
|
|
1093
|
+
if (this.shared.isDirectDisabled())
|
|
1094
|
+
return -58;
|
|
1086
1095
|
if (this.resident)
|
|
1087
1096
|
return this.residentIO(() => this.resident?.client?.tryWrite(handle, chunks, offset) ?? -6);
|
|
1088
1097
|
if (this.shared.publication)
|
|
@@ -1118,6 +1127,8 @@ export class FilesystemClient {
|
|
|
1118
1127
|
}
|
|
1119
1128
|
}
|
|
1120
1129
|
tryAppend(handle, chunks) {
|
|
1130
|
+
if (this.shared.isDirectDisabled())
|
|
1131
|
+
return -58;
|
|
1121
1132
|
if (this.resident)
|
|
1122
1133
|
return this.residentIO(() => this.resident?.client?.tryAppend(handle, chunks) ?? -6);
|
|
1123
1134
|
if (this.shared.publication)
|
|
@@ -1256,6 +1267,8 @@ export class FilesystemClient {
|
|
|
1256
1267
|
const stage = writing ? mapGet(this.stagedWrites, handle) : undefined;
|
|
1257
1268
|
if (this.revoked())
|
|
1258
1269
|
return { readable: true, writable: true, hangup: true };
|
|
1270
|
+
if (this.shared.isDirectDisabled())
|
|
1271
|
+
return { readable: !writing, writable: writing, hangup: false };
|
|
1259
1272
|
if (pending?.kind === "read")
|
|
1260
1273
|
return { readable: pending.completion.ready, writable: false, hangup: false };
|
|
1261
1274
|
if (pending && !pending.completion.ready || stage && !stage.completion.ready)
|
|
@@ -1316,8 +1329,9 @@ export class FilesystemClient {
|
|
|
1316
1329
|
try {
|
|
1317
1330
|
const epoch = this.version();
|
|
1318
1331
|
const key = `${directory}\x00${Number(followFinal) | Number(rooted) << 1}\x00${path}`;
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1332
|
+
const cacheable = !this.resident && !this.shared.publication && !this.shared.isClientCacheDisabled();
|
|
1333
|
+
const cached = cacheable ? this.paths.get(key, epoch) : undefined;
|
|
1334
|
+
if (cacheable && !(epoch & 1) && cached !== undefined)
|
|
1321
1335
|
return typeof cached === "number" ? cached : { ...cached };
|
|
1322
1336
|
return this.#resolveCold(key, [directory, path, followFinal, rooted]);
|
|
1323
1337
|
} catch (error) {
|
|
@@ -1334,23 +1348,26 @@ export class FilesystemClient {
|
|
|
1334
1348
|
}
|
|
1335
1349
|
}
|
|
1336
1350
|
#cacheResolved(key, epoch, resolved) {
|
|
1337
|
-
this.
|
|
1351
|
+
if (!this.shared.isClientCacheDisabled())
|
|
1352
|
+
this.paths.set(key, resolved, epoch);
|
|
1338
1353
|
return typeof resolved === "number" ? resolved : { ...resolved };
|
|
1339
1354
|
}
|
|
1340
1355
|
stat(handle) {
|
|
1341
1356
|
this.retain(handle);
|
|
1342
1357
|
try {
|
|
1343
|
-
const direct = this.resident ? undefined : this.shared.stat(handle, this.revoked);
|
|
1358
|
+
const direct = this.resident || this.shared.isDirectDisabled() ? undefined : this.shared.stat(handle, this.revoked);
|
|
1344
1359
|
if (direct)
|
|
1345
1360
|
return direct;
|
|
1346
1361
|
const epoch = this.version();
|
|
1347
|
-
const
|
|
1348
|
-
|
|
1362
|
+
const cacheable = !this.resident && !this.shared.publication && !this.shared.isClientCacheDisabled();
|
|
1363
|
+
const cached = cacheable ? this.stats.get(handle, epoch) : undefined;
|
|
1364
|
+
if (cacheable && !(epoch & 1) && cached)
|
|
1349
1365
|
return { ...cached };
|
|
1350
1366
|
const completion = this.submit("stat", [handle]);
|
|
1351
1367
|
try {
|
|
1352
1368
|
const stat = completion.wait();
|
|
1353
|
-
|
|
1369
|
+
if (cacheable)
|
|
1370
|
+
this.stats.set(handle, stat, completion.epoch);
|
|
1354
1371
|
return { ...stat };
|
|
1355
1372
|
} finally {
|
|
1356
1373
|
completion.release();
|
|
@@ -1372,14 +1389,17 @@ export class FilesystemClient {
|
|
|
1372
1389
|
}
|
|
1373
1390
|
cachedRead(handle, position) {
|
|
1374
1391
|
const epoch = this.version();
|
|
1375
|
-
|
|
1376
|
-
|
|
1392
|
+
const cacheable = !this.resident && !this.shared.publication && !this.shared.isClientCacheDisabled();
|
|
1393
|
+
let cached = cacheable ? this.reads.get(handle) : undefined;
|
|
1394
|
+
if (!cacheable || epoch & 1 || cached?.epoch !== epoch || position < cached.offset || position >= cached.offset + cached.bytes.length) {
|
|
1377
1395
|
const completion = this.submit("read", [handle, PAGE, position]);
|
|
1378
1396
|
try {
|
|
1379
1397
|
cached = { offset: position, bytes: completion.wait(), epoch: completion.epoch };
|
|
1380
|
-
if (
|
|
1381
|
-
this.reads.
|
|
1382
|
-
|
|
1398
|
+
if (cacheable) {
|
|
1399
|
+
if (this.reads.size >= 16)
|
|
1400
|
+
this.reads.clear();
|
|
1401
|
+
this.reads.set(handle, cached);
|
|
1402
|
+
}
|
|
1383
1403
|
} finally {
|
|
1384
1404
|
completion.release();
|
|
1385
1405
|
}
|
|
@@ -1432,6 +1452,8 @@ export class FilesystemClient {
|
|
|
1432
1452
|
return this.workspaceRead(handle, chunks, offset);
|
|
1433
1453
|
if (!(offset >= 0))
|
|
1434
1454
|
return -28;
|
|
1455
|
+
if (this.shared.isDirectDisabled())
|
|
1456
|
+
return this.readUnloaded(handle, chunks, offset);
|
|
1435
1457
|
const slot = this.directSlot(handle);
|
|
1436
1458
|
if (slot) {
|
|
1437
1459
|
try {
|
|
@@ -1477,6 +1499,26 @@ export class FilesystemClient {
|
|
|
1477
1499
|
if (!(offset >= 0))
|
|
1478
1500
|
return -28;
|
|
1479
1501
|
chunks = fixedWriteSources(chunks);
|
|
1502
|
+
if (this.shared.isDirectDisabled()) {
|
|
1503
|
+
try {
|
|
1504
|
+
let total = 0;
|
|
1505
|
+
for (let i = 0;i < chunks.length; i++)
|
|
1506
|
+
total += chunks[i].length;
|
|
1507
|
+
const limit = Math.min(total, 1024 * 1024);
|
|
1508
|
+
const data = new Uint8ArrayConstructor(limit);
|
|
1509
|
+
let at = 0;
|
|
1510
|
+
for (let i = 0;i < chunks.length && at < limit; i++) {
|
|
1511
|
+
const chunk = chunks[i];
|
|
1512
|
+
const count = Math.min(chunk.length, limit - at);
|
|
1513
|
+
if (count > 0)
|
|
1514
|
+
typedArraySet(data, chunk.subarray(0, count), at);
|
|
1515
|
+
at += count;
|
|
1516
|
+
}
|
|
1517
|
+
return this.call("write", [handle, offset], data);
|
|
1518
|
+
} catch (error) {
|
|
1519
|
+
return -errno(error);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1480
1522
|
const slot = this.directSlot(handle);
|
|
1481
1523
|
if (slot) {
|
|
1482
1524
|
let total = 0;
|
|
@@ -1544,6 +1586,23 @@ export class FilesystemClient {
|
|
|
1544
1586
|
let total = 0;
|
|
1545
1587
|
for (let i = 0;i < chunks.length; i++)
|
|
1546
1588
|
total += chunks[i].length;
|
|
1589
|
+
if (this.shared.isDirectDisabled()) {
|
|
1590
|
+
try {
|
|
1591
|
+
const limit = Math.min(total, 1024 * 1024);
|
|
1592
|
+
const data = new Uint8ArrayConstructor(limit);
|
|
1593
|
+
let at = 0;
|
|
1594
|
+
for (let i = 0;i < chunks.length && at < limit; i++) {
|
|
1595
|
+
const chunk = chunks[i];
|
|
1596
|
+
const count = Math.min(chunk.length, limit - at);
|
|
1597
|
+
if (count > 0)
|
|
1598
|
+
typedArraySet(data, chunk.subarray(0, count), at);
|
|
1599
|
+
at += count;
|
|
1600
|
+
}
|
|
1601
|
+
return this.call("append", [handle], data);
|
|
1602
|
+
} catch (error) {
|
|
1603
|
+
return -errno(error);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1547
1606
|
const fallback = () => {
|
|
1548
1607
|
const data = new Uint8ArrayConstructor(total);
|
|
1549
1608
|
let at = 0;
|
|
@@ -1644,7 +1703,7 @@ export class FilesystemClient {
|
|
|
1644
1703
|
resize(handle, size, truncate) {
|
|
1645
1704
|
if (this.shared.publication)
|
|
1646
1705
|
return this.publishedMetadata({ kind: "resize", handle, size, truncate });
|
|
1647
|
-
if (!this.shared.publication && mapHas(this.openHandles, handle) && this.shared.hasFile(handle)) {
|
|
1706
|
+
if (!this.shared.publication && !this.shared.isDirectDisabled() && mapHas(this.openHandles, handle) && this.shared.hasFile(handle)) {
|
|
1648
1707
|
try {
|
|
1649
1708
|
const result = this.shared.mutate(this.epoch, this.revoked, () => {
|
|
1650
1709
|
const info = this.shared.info(handle, this.revoked);
|
|
@@ -1670,7 +1729,7 @@ export class FilesystemClient {
|
|
|
1670
1729
|
return 28;
|
|
1671
1730
|
if (this.shared.publication)
|
|
1672
1731
|
return this.publishedMetadata({ kind: "setTimes", handle, atime, mtime });
|
|
1673
|
-
if (!this.shared.publication && mapHas(this.openHandles, handle) && this.shared.hasFile(handle)) {
|
|
1732
|
+
if (!this.shared.publication && !this.shared.isDirectDisabled() && mapHas(this.openHandles, handle) && this.shared.hasFile(handle)) {
|
|
1674
1733
|
try {
|
|
1675
1734
|
return this.shared.mutate(this.epoch, this.revoked, () => this.shared.setTimes(handle, atime, mtime, fileTimeNow(), this.revoked, this.connection.owner), this.connection.owner);
|
|
1676
1735
|
} catch (error) {
|
|
@@ -1716,13 +1775,15 @@ export class FilesystemClient {
|
|
|
1716
1775
|
}
|
|
1717
1776
|
readdir(handle) {
|
|
1718
1777
|
const epoch = this.version();
|
|
1719
|
-
const
|
|
1720
|
-
|
|
1778
|
+
const cacheable = !this.resident && !this.shared.publication && !this.shared.isClientCacheDisabled();
|
|
1779
|
+
const cached = cacheable ? this.readdirs.get(handle, epoch) : undefined;
|
|
1780
|
+
if (cacheable && !(epoch & 1) && cached)
|
|
1721
1781
|
return cached.map((entry) => ({ ...entry }));
|
|
1722
1782
|
const completion = this.submit("readdir", [handle]);
|
|
1723
1783
|
try {
|
|
1724
1784
|
const entries = completion.wait();
|
|
1725
|
-
|
|
1785
|
+
if (cacheable)
|
|
1786
|
+
this.readdirs.set(handle, entries, completion.epoch);
|
|
1726
1787
|
return entries.map((entry) => ({ ...entry }));
|
|
1727
1788
|
} finally {
|
|
1728
1789
|
completion.release();
|
|
@@ -1745,7 +1806,7 @@ export class FilesystemClient {
|
|
|
1745
1806
|
readlink(handle) {
|
|
1746
1807
|
this.retain(handle);
|
|
1747
1808
|
try {
|
|
1748
|
-
const direct = this.resident ? undefined : this.shared.stat(handle, this.revoked);
|
|
1809
|
+
const direct = this.resident || this.shared.isDirectDisabled() ? undefined : this.shared.stat(handle, this.revoked);
|
|
1749
1810
|
if (direct && direct.kind !== "symlink")
|
|
1750
1811
|
throw new FilesystemError(28);
|
|
1751
1812
|
return this.call("readlink", [handle]);
|
|
@@ -85,13 +85,20 @@ export function checkDirectoryPage(cookie, byteLength) {
|
|
|
85
85
|
function entryBytes(entry) {
|
|
86
86
|
return entry.bytes ??= encoder.encode(entry.name);
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
const MAX_TAGGED_RAW_COOKIE = (1n << 48n) - 1n;
|
|
89
|
+
function encodeEntry(output, view, offset, entry, cookieTag) {
|
|
89
90
|
const bytes = entryBytes(entry);
|
|
90
91
|
const remaining = output.length - offset;
|
|
91
92
|
const header = remaining < 24 ? new Uint8Array(24) : output;
|
|
92
93
|
const headerView = remaining < 24 ? new DataView(header.buffer) : view;
|
|
93
94
|
const start = remaining < 24 ? 0 : offset;
|
|
94
|
-
|
|
95
|
+
let wireCookie = entry.cookie;
|
|
96
|
+
if (cookieTag && entry.cookie >= 3n) {
|
|
97
|
+
if (entry.cookie > MAX_TAGGED_RAW_COOKIE)
|
|
98
|
+
throw new FilesystemError(61, "directory cookies exhausted");
|
|
99
|
+
wireCookie = cookieTag << 48n | entry.cookie;
|
|
100
|
+
}
|
|
101
|
+
headerView.setBigUint64(start, wireCookie, true);
|
|
95
102
|
headerView.setBigUint64(start + 8, BigInt(entry.ino), true);
|
|
96
103
|
headerView.setUint32(start + 16, bytes.length, true);
|
|
97
104
|
headerView.setUint8(start + 20, entry.kind === "directory" ? 3 : entry.kind === "symlink" ? 7 : entry.kind === "socket" ? 6 : 4);
|
|
@@ -164,9 +171,10 @@ export class DirectoryPages {
|
|
|
164
171
|
}
|
|
165
172
|
return size;
|
|
166
173
|
}
|
|
167
|
-
page(cookie, byteLength, ino, parent) {
|
|
174
|
+
page(cookie, byteLength, ino, parent, cookieTag, maxBytes, hardCapBytes) {
|
|
168
175
|
if (!byteLength)
|
|
169
176
|
return new Uint8Array;
|
|
177
|
+
const limit = maxBytes !== undefined ? Math.min(byteLength, maxBytes) : byteLength;
|
|
170
178
|
const entries = [];
|
|
171
179
|
let size = 0;
|
|
172
180
|
const append = (entry) => {
|
|
@@ -183,13 +191,20 @@ export class DirectoryPages {
|
|
|
183
191
|
cookie: 2n,
|
|
184
192
|
bytes: new Uint8Array([46, 46])
|
|
185
193
|
});
|
|
186
|
-
if (size < byteLength)
|
|
187
|
-
|
|
188
|
-
|
|
194
|
+
if (size < byteLength) {
|
|
195
|
+
const scanLimit = maxBytes !== undefined ? limit + 1 : byteLength;
|
|
196
|
+
size = this.appendEntries(entries, cookie, scanLimit, size);
|
|
197
|
+
}
|
|
198
|
+
const actual = Math.min(byteLength, size);
|
|
199
|
+
if (maxBytes !== undefined && actual > maxBytes) {
|
|
200
|
+
const overHardCap = hardCapBytes !== undefined && actual > hardCapBytes;
|
|
201
|
+
throw new FilesystemError(overHardCap ? 22 : 6, overHardCap ? "directory page exceeds maximum transfer size" : "download budget exhausted");
|
|
202
|
+
}
|
|
203
|
+
const output = new Uint8Array(actual);
|
|
189
204
|
const view = new DataView(output.buffer);
|
|
190
205
|
let used = 0;
|
|
191
206
|
for (const entry of entries)
|
|
192
|
-
used = encodeEntry(output, view, used, entry);
|
|
207
|
+
used = encodeEntry(output, view, used, entry, cookieTag);
|
|
193
208
|
return output;
|
|
194
209
|
}
|
|
195
210
|
}
|
package/dist/fs/guest-watch.js
CHANGED
|
@@ -27,6 +27,7 @@ export class GuestWatchTable {
|
|
|
27
27
|
fs;
|
|
28
28
|
watches = new MapConstructor;
|
|
29
29
|
nextId = 1;
|
|
30
|
+
revocationNotified = false;
|
|
30
31
|
constructor(fs) {
|
|
31
32
|
this.fs = fs;
|
|
32
33
|
}
|
|
@@ -42,7 +43,9 @@ export class GuestWatchTable {
|
|
|
42
43
|
return active;
|
|
43
44
|
}
|
|
44
45
|
pending() {
|
|
45
|
-
|
|
46
|
+
if (this.fs.revoked)
|
|
47
|
+
return !!this.fs.remote && !this.revocationNotified && this.active;
|
|
48
|
+
return this.hasPending(false);
|
|
46
49
|
}
|
|
47
50
|
ready() {
|
|
48
51
|
if (!mapSize(this.watches))
|
|
@@ -101,10 +104,13 @@ export class GuestWatchTable {
|
|
|
101
104
|
this.watches = new MapConstructor;
|
|
102
105
|
}
|
|
103
106
|
refill(watch) {
|
|
104
|
-
if (this.fs.revoked)
|
|
107
|
+
if (this.fs.revoked) {
|
|
108
|
+
if (this.fs.remote)
|
|
109
|
+
this.revocationNotified = true;
|
|
105
110
|
return failure(ECANCELED);
|
|
111
|
+
}
|
|
106
112
|
const generation = atomicsLoad(this.fs.cells, 3);
|
|
107
|
-
if (generation === watch.observed)
|
|
113
|
+
if (!this.fs.remote && generation === watch.observed)
|
|
108
114
|
return failure(EAGAIN);
|
|
109
115
|
const previous = watch.observed;
|
|
110
116
|
watch.observed = generation;
|
package/dist/fs/idle-database.js
CHANGED
|
@@ -73,7 +73,7 @@ export async function isWorkspace(database) {
|
|
|
73
73
|
return false;
|
|
74
74
|
if (!["journal", "data"].every((name) => database.objectStoreNames.contains(name)))
|
|
75
75
|
return false;
|
|
76
|
-
return typeof epoch === "number" && Number.isSafeInteger(epoch) && epoch > 0 && keys.some((key) => key === 0 || key === 1) && keys.every((key) => key === 0 || key === 1 || key === "epoch" || key === "active" || key === "identity" || key === "format");
|
|
76
|
+
return typeof epoch === "number" && Number.isSafeInteger(epoch) && epoch > 0 && keys.some((key) => key === 0 || key === 1) && keys.every((key) => key === 0 || key === 1 || key === "epoch" || key === "lastExclusiveEpoch" || key === "active" || key === "identity" || key === "format");
|
|
77
77
|
}
|
|
78
78
|
async function inspectStoredName(name) {
|
|
79
79
|
const maintenance = await maintenanceLock(navigator.locks, name, "shared");
|
package/dist/fs/idle-owner.js
CHANGED
|
@@ -149,7 +149,30 @@ async function finishIdleClaim(database, debts, maintenance) {
|
|
|
149
149
|
throwCleanupFailures(failures, "Idle database claim cleanup failed");
|
|
150
150
|
}
|
|
151
151
|
async function requestIdleWriter(locks, name, callback) {
|
|
152
|
-
|
|
152
|
+
let writerLifetime;
|
|
153
|
+
let requestError;
|
|
154
|
+
await locks.request(`bun-wasm:filesystem:indexeddb-arb:${name}`, { mode: "shared", ifAvailable: true }, async (arb) => {
|
|
155
|
+
if (!arb) {
|
|
156
|
+
await callback(null);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const entered = Promise.withResolvers();
|
|
160
|
+
try {
|
|
161
|
+
writerLifetime = locks.request(`bun-wasm:filesystem:indexeddb:${name}`, { mode: "exclusive", ifAvailable: true }, async (lock) => {
|
|
162
|
+
entered.resolve();
|
|
163
|
+
await callback(lock);
|
|
164
|
+
});
|
|
165
|
+
} catch (value) {
|
|
166
|
+
requestError = { value };
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
writerLifetime.catch(() => entered.resolve());
|
|
170
|
+
await entered.promise;
|
|
171
|
+
});
|
|
172
|
+
if (requestError)
|
|
173
|
+
throw requestError.value;
|
|
174
|
+
if (writerLifetime)
|
|
175
|
+
await writerLifetime;
|
|
153
176
|
}
|
|
154
177
|
export async function claimIdleDeletion(name, signal) {
|
|
155
178
|
signal?.throwIfAborted();
|
|
@@ -159,18 +182,26 @@ export async function claimIdleDeletion(name, signal) {
|
|
|
159
182
|
const maintenance = await maintenanceLock(locks, name, "exclusive", signal);
|
|
160
183
|
if (maintenance === "busy")
|
|
161
184
|
return "busy";
|
|
162
|
-
|
|
185
|
+
let writer = "busy";
|
|
186
|
+
try {
|
|
187
|
+
writer = await locks.request(`bun-wasm:filesystem:indexeddb-arb:${name}`, { mode: "shared", ifAvailable: true }, async (arb) => {
|
|
188
|
+
if (!arb)
|
|
189
|
+
return "busy";
|
|
190
|
+
return holdLock(locks, `bun-wasm:filesystem:indexeddb:${name}`, { mode: "exclusive", ifAvailable: true }, signal);
|
|
191
|
+
});
|
|
192
|
+
} catch (error) {
|
|
163
193
|
await maintenance.release();
|
|
164
194
|
throw error;
|
|
165
|
-
}
|
|
195
|
+
}
|
|
166
196
|
if (writer === "busy") {
|
|
167
197
|
await maintenance.release();
|
|
168
198
|
return "busy";
|
|
169
199
|
}
|
|
200
|
+
const ownedWriter = writer;
|
|
170
201
|
return {
|
|
171
202
|
remove: () => deleteOwnedDatabase(name, signal),
|
|
172
203
|
async release() {
|
|
173
|
-
await
|
|
204
|
+
await ownedWriter.release();
|
|
174
205
|
await maintenance.release();
|
|
175
206
|
}
|
|
176
207
|
};
|