@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/fs/persistent.ts
CHANGED
|
@@ -56,6 +56,10 @@ function copyTimes(node: Node, stat: FileStat): void {
|
|
|
56
56
|
export class PersistentBackend extends MemoryBackend {
|
|
57
57
|
private readonly pressure: CheckpointPressure;
|
|
58
58
|
private nodes = new Map<number, Node>();
|
|
59
|
+
private byFileId = new Map<bigint, Node>();
|
|
60
|
+
private readonly initialWorkspaceId: string;
|
|
61
|
+
private readonly initialEra: bigint;
|
|
62
|
+
private readonly loadedIndex: boolean;
|
|
59
63
|
private detached = new WeakSet<Node>();
|
|
60
64
|
private links = new Map<number, number>();
|
|
61
65
|
private removed = new Set<number>();
|
|
@@ -91,11 +95,15 @@ export class PersistentBackend extends MemoryBackend {
|
|
|
91
95
|
sharedRoot?: MemoryBackendSharedRoot,
|
|
92
96
|
) {
|
|
93
97
|
super(fs, reservation, startupRoot, undefined, sharedRoot);
|
|
98
|
+
this.initialWorkspaceId = reservation.workspace;
|
|
99
|
+
this.initialEra = reservation.era;
|
|
100
|
+
this.loadedIndex = index !== undefined;
|
|
94
101
|
this.pressure = new CheckpointPressure(checkpointLimits);
|
|
95
102
|
const visit = (node: Node) => {
|
|
96
103
|
this.links.set(node.ino, (this.links.get(node.ino) ?? 0) + 1);
|
|
97
104
|
if (this.nodes.has(node.ino)) return;
|
|
98
105
|
this.nodes.set(node.ino, node);
|
|
106
|
+
if (node.identity) this.byFileId.set(node.identity.id, node);
|
|
99
107
|
if (node.kind === "dir") for (const child of node.children.values()) visit(child);
|
|
100
108
|
};
|
|
101
109
|
visit(fs.root);
|
|
@@ -112,11 +120,46 @@ export class PersistentBackend extends MemoryBackend {
|
|
|
112
120
|
fs.onChange = (node) => {
|
|
113
121
|
if (!this.detached.has(node)) {
|
|
114
122
|
this.nodes.set(node.ino, node);
|
|
123
|
+
if (node.identity) this.byFileId.set(node.identity.id, node);
|
|
115
124
|
this.dirty.add(node);
|
|
116
125
|
}
|
|
117
126
|
};
|
|
118
127
|
this.startTimer(intervalMs);
|
|
119
128
|
}
|
|
129
|
+
get initialReservationEra(): bigint {
|
|
130
|
+
return this.initialEra;
|
|
131
|
+
}
|
|
132
|
+
get hasLoadedIndex(): boolean {
|
|
133
|
+
return this.loadedIndex;
|
|
134
|
+
}
|
|
135
|
+
async verifyStorageEpoch(signal?: AbortSignal): Promise<boolean> {
|
|
136
|
+
if ("verifyEpoch" in this.storage && typeof this.storage.verifyEpoch === "function") {
|
|
137
|
+
return (this.storage as { verifyEpoch(s?: AbortSignal): Promise<boolean> }).verifyEpoch(
|
|
138
|
+
signal,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
nodeByFileId(fileId: bigint): Node | undefined {
|
|
144
|
+
const node = this.byFileId.get(fileId);
|
|
145
|
+
if (node && node.identity?.id === fileId) return node;
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
resolveNodePublic(path: string): Node | undefined {
|
|
149
|
+
return this.resolveNode(path);
|
|
150
|
+
}
|
|
151
|
+
ensureLoadedHandle(handle: FileHandle): void | Promise<void> {
|
|
152
|
+
return this.ensureLoaded(handle);
|
|
153
|
+
}
|
|
154
|
+
isTerminallyFailed(): boolean {
|
|
155
|
+
return this.storage.isTerminallyFailed?.() ?? false;
|
|
156
|
+
}
|
|
157
|
+
terminalFailureReason(): unknown {
|
|
158
|
+
return this.storage.terminalFailureReason?.();
|
|
159
|
+
}
|
|
160
|
+
setTerminalFailureListener(listener: (reason: unknown) => void): void {
|
|
161
|
+
this.storage.setTerminalFailureListener?.(listener);
|
|
162
|
+
}
|
|
120
163
|
private startTimer(intervalMs: number): void {
|
|
121
164
|
if (intervalMs > 0)
|
|
122
165
|
this.timer = setInterval(() => {
|
|
@@ -131,11 +174,15 @@ export class PersistentBackend extends MemoryBackend {
|
|
|
131
174
|
dirtyLimits?: Partial<DirtyLimits> | false;
|
|
132
175
|
startupRoot?: MemoryBudget;
|
|
133
176
|
sharedRoot?: MemoryBackendSharedRoot;
|
|
177
|
+
signal?: AbortSignal;
|
|
134
178
|
} = {},
|
|
135
179
|
): Promise<PersistentBackend> {
|
|
180
|
+
options.signal?.throwIfAborted();
|
|
136
181
|
const index = await storage.load();
|
|
182
|
+
options.signal?.throwIfAborted();
|
|
137
183
|
if (index) validatePersistedIndex(index);
|
|
138
184
|
const reservation = await storage.reserveIdentity(index?.nodes[0]?.identity?.workspace);
|
|
185
|
+
options.signal?.throwIfAborted();
|
|
139
186
|
validateReservation(index, reservation);
|
|
140
187
|
if (!index)
|
|
141
188
|
return new PersistentBackend(
|
|
@@ -166,9 +213,11 @@ export class PersistentBackend extends MemoryBackend {
|
|
|
166
213
|
try {
|
|
167
214
|
if (!index.nodes[0]?.identity) {
|
|
168
215
|
await storage.flush();
|
|
216
|
+
options.signal?.throwIfAborted();
|
|
169
217
|
for (const node of backend.nodes.values()) backend.dirty.add(node);
|
|
170
|
-
await backend.flush();
|
|
218
|
+
await backend.flush(undefined, options.signal);
|
|
171
219
|
}
|
|
220
|
+
options.signal?.throwIfAborted();
|
|
172
221
|
backend.startTimer(options.intervalMs ?? 50);
|
|
173
222
|
return backend;
|
|
174
223
|
} catch (error) {
|
|
@@ -183,6 +232,7 @@ export class PersistentBackend extends MemoryBackend {
|
|
|
183
232
|
else this.links.delete(node.ino);
|
|
184
233
|
if (delta === 1 && previous === 0) {
|
|
185
234
|
this.nodes.set(node.ino, node);
|
|
235
|
+
if (node.identity) this.byFileId.set(node.identity.id, node);
|
|
186
236
|
this.detached.delete(node);
|
|
187
237
|
const key = this.detachedKeys.get(node.ino);
|
|
188
238
|
if (key) {
|
|
@@ -207,6 +257,7 @@ export class PersistentBackend extends MemoryBackend {
|
|
|
207
257
|
}
|
|
208
258
|
}
|
|
209
259
|
protected identityChanged(node: Node): void {
|
|
260
|
+
if (node.identity) this.byFileId.set(node.identity.id, node);
|
|
210
261
|
if (this.isLinked(node)) this.dirty.add(node);
|
|
211
262
|
}
|
|
212
263
|
protected isLinked(node: Node): boolean {
|
|
@@ -945,6 +996,24 @@ export class PersistentBackend extends MemoryBackend {
|
|
|
945
996
|
this.coldReads.clear();
|
|
946
997
|
}
|
|
947
998
|
}
|
|
999
|
+
/** Retire persistence without attempting a final checkpoint, joining all admitted work and
|
|
1000
|
+
* closing storage + watch account cleanly before any shared-memory remount reset. */
|
|
1001
|
+
async retireFenced(options: { throwOnStorageCloseError?: boolean } = {}): Promise<void> {
|
|
1002
|
+
this.stopPersistence();
|
|
1003
|
+
const work = Array.from(
|
|
1004
|
+
new Set(Array.from(this.admittedWork).concat([this.lastCommit, this.tail])),
|
|
1005
|
+
);
|
|
1006
|
+
await Promise.allSettled(work);
|
|
1007
|
+
this.coldReads.clear();
|
|
1008
|
+
let closeFailure: { failed: true; reason: unknown } | undefined;
|
|
1009
|
+
try {
|
|
1010
|
+
await this.storage.close();
|
|
1011
|
+
} catch (reason) {
|
|
1012
|
+
if (options.throwOnStorageCloseError) closeFailure = { failed: true, reason };
|
|
1013
|
+
}
|
|
1014
|
+
this.watchAccount.close();
|
|
1015
|
+
if (closeFailure) throw closeFailure.reason;
|
|
1016
|
+
}
|
|
948
1017
|
close(): Promise<void> {
|
|
949
1018
|
if (this.closing) return this.closing;
|
|
950
1019
|
const owner = Promise.withResolvers<void>();
|
package/fs/protocol.ts
CHANGED
|
@@ -406,7 +406,7 @@ export function createFilesystemConnection(
|
|
|
406
406
|
/** The service lifetime is shared even by processes with independent parent lifetimes. */
|
|
407
407
|
export function revokeFilesystemService(connection: FilesystemIdentity): void {
|
|
408
408
|
Atomics.store(new Int32Array(connection.ownerStates), 0, 1);
|
|
409
|
-
wakeFilesystemWatch(connection.shared);
|
|
409
|
+
wakeFilesystemWatch(connection.shared, true);
|
|
410
410
|
wake(connection);
|
|
411
411
|
}
|
|
412
412
|
export function revokeFilesystem(connection: FilesystemIdentity): void {
|