@waffle-os/runtime 0.0.147 → 0.0.149
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/process-broker.ts +6 -3
- package/browser/run-command.ts +18 -7
- 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/process-broker.js +3 -2
- package/dist/browser/run-command.js +8 -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/proc/registry.js +8 -8
- package/dist/proc/start-command.js +10 -0
- package/dist/proc/supervisor.js +4 -4
- 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/proc/registry.ts +13 -19
- package/proc/start-command.ts +29 -0
- package/proc/supervisor.ts +8 -6
- package/runtime.ts +12 -3
- package/tooling/program/program-transformer.json +1 -1
package/fs/directory-pages.ts
CHANGED
|
@@ -93,13 +93,27 @@ function entryBytes(entry: Entry): Uint8Array {
|
|
|
93
93
|
return (entry.bytes ??= encoder.encode(entry.name));
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
const MAX_TAGGED_RAW_COOKIE = (1n << 48n) - 1n;
|
|
97
|
+
|
|
98
|
+
function encodeEntry(
|
|
99
|
+
output: Uint8Array,
|
|
100
|
+
view: DataView,
|
|
101
|
+
offset: number,
|
|
102
|
+
entry: Entry,
|
|
103
|
+
cookieTag?: bigint,
|
|
104
|
+
): number {
|
|
97
105
|
const bytes = entryBytes(entry);
|
|
98
106
|
const remaining = output.length - offset;
|
|
99
107
|
const header = remaining < 24 ? new Uint8Array(24) : output;
|
|
100
108
|
const headerView = remaining < 24 ? new DataView(header.buffer) : view;
|
|
101
109
|
const start = remaining < 24 ? 0 : offset;
|
|
102
|
-
|
|
110
|
+
let wireCookie = entry.cookie;
|
|
111
|
+
if (cookieTag && entry.cookie >= 3n) {
|
|
112
|
+
if (entry.cookie > MAX_TAGGED_RAW_COOKIE)
|
|
113
|
+
throw new FilesystemError(61, "directory cookies exhausted");
|
|
114
|
+
wireCookie = (cookieTag << 48n) | entry.cookie;
|
|
115
|
+
}
|
|
116
|
+
headerView.setBigUint64(start, wireCookie, true);
|
|
103
117
|
headerView.setBigUint64(start + 8, BigInt(entry.ino), true);
|
|
104
118
|
headerView.setUint32(start + 16, bytes.length, true);
|
|
105
119
|
headerView.setUint8(
|
|
@@ -177,8 +191,17 @@ export class DirectoryPages {
|
|
|
177
191
|
}
|
|
178
192
|
return size;
|
|
179
193
|
}
|
|
180
|
-
page(
|
|
194
|
+
page(
|
|
195
|
+
cookie: bigint,
|
|
196
|
+
byteLength: number,
|
|
197
|
+
ino: number,
|
|
198
|
+
parent: number,
|
|
199
|
+
cookieTag?: bigint,
|
|
200
|
+
maxBytes?: number,
|
|
201
|
+
hardCapBytes?: number,
|
|
202
|
+
): Uint8Array {
|
|
181
203
|
if (!byteLength) return new Uint8Array();
|
|
204
|
+
const limit = maxBytes !== undefined ? Math.min(byteLength, maxBytes) : byteLength;
|
|
182
205
|
const entries: Entry[] = [];
|
|
183
206
|
let size = 0;
|
|
184
207
|
const append = (entry: Entry) => {
|
|
@@ -195,11 +218,22 @@ export class DirectoryPages {
|
|
|
195
218
|
cookie: 2n,
|
|
196
219
|
bytes: new Uint8Array([46, 46]),
|
|
197
220
|
});
|
|
198
|
-
if (size < byteLength)
|
|
199
|
-
|
|
221
|
+
if (size < byteLength) {
|
|
222
|
+
const scanLimit = maxBytes !== undefined ? limit + 1 : byteLength;
|
|
223
|
+
size = this.appendEntries(entries, cookie, scanLimit, size);
|
|
224
|
+
}
|
|
225
|
+
const actual = Math.min(byteLength, size);
|
|
226
|
+
if (maxBytes !== undefined && actual > maxBytes) {
|
|
227
|
+
const overHardCap = hardCapBytes !== undefined && actual > hardCapBytes;
|
|
228
|
+
throw new FilesystemError(
|
|
229
|
+
overHardCap ? 22 : 6,
|
|
230
|
+
overHardCap ? "directory page exceeds maximum transfer size" : "download budget exhausted",
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
const output = new Uint8Array(actual);
|
|
200
234
|
const view = new DataView(output.buffer);
|
|
201
235
|
let used = 0;
|
|
202
|
-
for (const entry of entries) used = encodeEntry(output, view, used, entry);
|
|
236
|
+
for (const entry of entries) used = encodeEntry(output, view, used, entry, cookieTag);
|
|
203
237
|
return output;
|
|
204
238
|
}
|
|
205
239
|
}
|
package/fs/guest-watch.ts
CHANGED
|
@@ -59,6 +59,7 @@ function failure(errno: number): GuestWatchRead {
|
|
|
59
59
|
export class GuestWatchTable implements GuestWatchReadiness {
|
|
60
60
|
private watches = new MapConstructor<number, Watch>();
|
|
61
61
|
private nextId = 1;
|
|
62
|
+
private revocationNotified = false;
|
|
62
63
|
|
|
63
64
|
constructor(private readonly fs: WatchFileSystem) {}
|
|
64
65
|
|
|
@@ -75,7 +76,8 @@ export class GuestWatchTable implements GuestWatchReadiness {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
pending(): boolean {
|
|
78
|
-
|
|
79
|
+
if (this.fs.revoked) return !!this.fs.remote && !this.revocationNotified && this.active;
|
|
80
|
+
return this.hasPending(false);
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
/** A read may return records, end or an error; never consumes watch state. */
|
|
@@ -146,9 +148,12 @@ export class GuestWatchTable implements GuestWatchReadiness {
|
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
private refill(watch: Watch): GuestWatchRead | undefined {
|
|
149
|
-
if (this.fs.revoked)
|
|
151
|
+
if (this.fs.revoked) {
|
|
152
|
+
if (this.fs.remote) this.revocationNotified = true;
|
|
153
|
+
return failure(ECANCELED);
|
|
154
|
+
}
|
|
150
155
|
const generation = atomicsLoad(this.fs.cells, 3);
|
|
151
|
-
if (generation === watch.observed) return failure(EAGAIN);
|
|
156
|
+
if (!this.fs.remote && generation === watch.observed) return failure(EAGAIN);
|
|
152
157
|
// Set before the call: a commit after the service drains moves the counter again. A failed
|
|
153
158
|
// call drained nothing, so the watch stays pending for the retry.
|
|
154
159
|
const previous = watch.observed;
|
package/fs/idle-database.ts
CHANGED
package/fs/idle-owner.ts
CHANGED
|
@@ -182,11 +182,36 @@ async function requestIdleWriter(
|
|
|
182
182
|
name: string,
|
|
183
183
|
callback: (lock: unknown | null) => Promise<void>,
|
|
184
184
|
): Promise<void> {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
let writerLifetime: Promise<void> | undefined;
|
|
186
|
+
let requestError: { readonly value: unknown } | undefined;
|
|
187
|
+
await locks.request(
|
|
188
|
+
`bun-wasm:filesystem:indexeddb-arb:${name}`,
|
|
189
|
+
{ mode: "shared", ifAvailable: true },
|
|
190
|
+
async (arb) => {
|
|
191
|
+
if (!arb) {
|
|
192
|
+
await callback(null);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const entered = Promise.withResolvers<void>();
|
|
196
|
+
try {
|
|
197
|
+
writerLifetime = locks.request(
|
|
198
|
+
`bun-wasm:filesystem:indexeddb:${name}`,
|
|
199
|
+
{ mode: "exclusive", ifAvailable: true },
|
|
200
|
+
async (lock) => {
|
|
201
|
+
entered.resolve();
|
|
202
|
+
await callback(lock);
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
} catch (value) {
|
|
206
|
+
requestError = { value };
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
void writerLifetime.catch(() => entered.resolve());
|
|
210
|
+
await entered.promise;
|
|
211
|
+
},
|
|
189
212
|
);
|
|
213
|
+
if (requestError) throw requestError.value;
|
|
214
|
+
if (writerLifetime) await writerLifetime;
|
|
190
215
|
}
|
|
191
216
|
|
|
192
217
|
/** Claims a workspace database for deletion without reading its records, so an unreadable
|
|
@@ -201,23 +226,34 @@ export async function claimIdleDeletion(
|
|
|
201
226
|
const locks = navigator.locks;
|
|
202
227
|
const maintenance = await maintenanceLock(locks, name, "exclusive", signal);
|
|
203
228
|
if (maintenance === "busy") return "busy";
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
229
|
+
let writer: Awaited<ReturnType<typeof holdLock>> | "busy" = "busy";
|
|
230
|
+
try {
|
|
231
|
+
writer = await locks.request(
|
|
232
|
+
`bun-wasm:filesystem:indexeddb-arb:${name}`,
|
|
233
|
+
{ mode: "shared", ifAvailable: true },
|
|
234
|
+
async (arb) => {
|
|
235
|
+
if (!arb) return "busy" as const;
|
|
236
|
+
return holdLock(
|
|
237
|
+
locks,
|
|
238
|
+
`bun-wasm:filesystem:indexeddb:${name}`,
|
|
239
|
+
{ mode: "exclusive", ifAvailable: true },
|
|
240
|
+
signal,
|
|
241
|
+
);
|
|
242
|
+
},
|
|
243
|
+
);
|
|
244
|
+
} catch (error) {
|
|
210
245
|
await maintenance.release();
|
|
211
246
|
throw error;
|
|
212
|
-
}
|
|
247
|
+
}
|
|
213
248
|
if (writer === "busy") {
|
|
214
249
|
await maintenance.release();
|
|
215
250
|
return "busy";
|
|
216
251
|
}
|
|
252
|
+
const ownedWriter = writer;
|
|
217
253
|
return {
|
|
218
254
|
remove: () => deleteOwnedDatabase(name, signal),
|
|
219
255
|
async release() {
|
|
220
|
-
await
|
|
256
|
+
await ownedWriter.release();
|
|
221
257
|
await maintenance.release();
|
|
222
258
|
},
|
|
223
259
|
};
|