@waffle-os/runtime 0.0.155 → 0.0.157
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 +11 -1
- package/browser/preview-protocol.ts +2 -0
- package/browser/preview.ts +128 -18
- package/browser/runtime-terminals.ts +65 -24
- package/browser/shared-fs.ts +141 -14
- package/browser/worker.ts +73 -6
- package/core/descriptors.ts +19 -2
- package/core/devices.ts +237 -2
- package/core/fd-reopen.ts +105 -20
- package/core/filesystem.ts +79 -0
- package/core/index.ts +4 -0
- package/core/open-file.ts +212 -18
- package/core/wasi.ts +449 -47
- package/dist/browser/filesystem-backend.js +4 -2
- package/dist/browser/preview.js +120 -17
- package/dist/browser/runtime-terminals.js +53 -10
- package/dist/browser/shared-fs.js +124 -11
- package/dist/browser/worker.js +59 -6
- package/dist/core/descriptors.js +9 -1
- package/dist/core/devices.js +211 -1
- package/dist/core/fd-reopen.js +79 -18
- package/dist/core/filesystem.js +14 -0
- package/dist/core/open-file.js +166 -13
- package/dist/core/wasi.js +402 -29
- package/dist/fs/backend.js +51 -3
- package/dist/fs/client.js +204 -7
- package/dist/fs/cold-read-cache.js +23 -0
- package/dist/fs/index.js +21 -1
- package/dist/fs/indexeddb.js +30 -2
- package/dist/fs/locks.js +1112 -0
- package/dist/fs/memory.js +126 -2
- package/dist/fs/multitab-backend.js +317 -196
- package/dist/fs/multitab-protocol.js +2 -0
- package/dist/fs/persistent.js +32 -7
- package/dist/fs/protocol.js +9 -3
- package/dist/fs/service.js +387 -22
- package/dist/fs/shared.js +54 -1
- package/dist/fs/storage-geometry.js +2 -0
- package/dist/interrupt/rewriter-internal.js +4 -1
- package/dist/proc/abi.js +80 -6
- package/dist/proc/errors.js +1 -0
- package/dist/proc/filesystem-codec.js +40 -9
- package/dist/proc/index.js +10 -1
- package/dist/proc/pty.js +193 -0
- package/dist/proc/worker-client.js +11 -2
- package/dist/proc/worker-pipes.js +51 -0
- package/dist/runtime.js +11 -2
- package/dist/search/engine.js +53 -0
- package/dist/tooling/program/program-transformer.json +1 -1
- package/fs/backend.ts +54 -2
- package/fs/client.ts +230 -6
- package/fs/cold-read-cache.ts +38 -0
- package/fs/index.ts +22 -1
- package/fs/indexeddb.ts +36 -2
- package/fs/locks.ts +1406 -0
- package/fs/memory.ts +132 -1
- package/fs/multitab-backend.ts +563 -304
- package/fs/multitab-protocol.ts +2 -0
- package/fs/persistent.ts +46 -4
- package/fs/protocol.ts +17 -5
- package/fs/service.ts +469 -23
- package/fs/shared.ts +60 -2
- package/fs/storage-geometry.ts +3 -0
- package/index.ts +2 -0
- package/interrupt/rewriter-internal.ts +4 -1
- package/package.json +2 -2
- package/proc/abi.ts +79 -6
- package/proc/errors.ts +1 -0
- package/proc/filesystem-codec.ts +39 -9
- package/proc/index.ts +11 -0
- package/proc/pty.ts +227 -0
- package/proc/worker-client.ts +28 -6
- package/proc/worker-pipes.ts +57 -0
- package/runtime.ts +12 -2
- package/search/engine.ts +49 -0
- package/testing/indexeddb-storage-browser.ts +173 -2
- package/tooling/program/program-transformer.json +1 -1
package/fs/memory.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { validateMachineId } from "../core/devices.js";
|
|
1
2
|
import { DirectoryPages, checkDirectoryPage } from "./directory-pages.js";
|
|
3
|
+
import { LockTable } from "./locks.js";
|
|
2
4
|
import { utf8ByteLength } from "./utf8-size.js";
|
|
3
5
|
import type { FileIdentity } from "./file-identity.js";
|
|
4
6
|
import type { NodeMetadata } from "./workspace-types.js";
|
|
@@ -6,7 +8,10 @@ import {
|
|
|
6
8
|
permissionsFor,
|
|
7
9
|
FilesystemError,
|
|
8
10
|
fileTimeNow,
|
|
11
|
+
PROBE_PATH_LIMIT,
|
|
12
|
+
type FileLockSystem,
|
|
9
13
|
type FileTime,
|
|
14
|
+
type ProbeKind,
|
|
10
15
|
type SocketBinding,
|
|
11
16
|
} from "../core/filesystem.js";
|
|
12
17
|
import {
|
|
@@ -373,6 +378,32 @@ export class MemFS implements FileSystem {
|
|
|
373
378
|
private nodeHandles = new WeakMap<Node, FileHandle>();
|
|
374
379
|
private nextHandle = 0;
|
|
375
380
|
private references = new Map<FileHandle, number>();
|
|
381
|
+
private lockTable?: LockTable;
|
|
382
|
+
private lockAdapter?: FileLockSystem;
|
|
383
|
+
get locks(): FileLockSystem {
|
|
384
|
+
if (this.lockAdapter) return this.lockAdapter;
|
|
385
|
+
const table = (this.lockTable ??= new LockTable());
|
|
386
|
+
const inoOf = (handle: FileHandle): number => this.nodeForHandle(handle).ino;
|
|
387
|
+
this.lockAdapter = {
|
|
388
|
+
flock: (handle, ofdId, operation) =>
|
|
389
|
+
table.flock(inoOf(handle), ofdId, 0, operation, false, handle, false).errno,
|
|
390
|
+
setRangeLock: (handle, ofdId, pid, range, blocking) =>
|
|
391
|
+
table.setRangeLock(inoOf(handle), ofdId, 0, pid, range, blocking, false, handle, pid, false)
|
|
392
|
+
.errno,
|
|
393
|
+
getRangeLock: (handle, ofdId, range, pid = 1) =>
|
|
394
|
+
table.getRangeLock(inoOf(handle), ofdId, 0, range, pid),
|
|
395
|
+
releaseOfd: (handle, ofdId) => {
|
|
396
|
+
const node = this.handles.get(handle);
|
|
397
|
+
if (node) table.releaseOfd(node.ino, ofdId, 0);
|
|
398
|
+
},
|
|
399
|
+
releasePosix: (handle, pid = 1) => {
|
|
400
|
+
const node = this.handles.get(handle);
|
|
401
|
+
if (node) table.releasePosix(node.ino, pid);
|
|
402
|
+
},
|
|
403
|
+
hasActivePosixLocks: () => table.hasActivePosixLocks(),
|
|
404
|
+
};
|
|
405
|
+
return this.lockAdapter;
|
|
406
|
+
}
|
|
376
407
|
private directoryParents = new WeakMap<DirNode, DirNode>();
|
|
377
408
|
private removedDirectories = new WeakSet<DirNode>();
|
|
378
409
|
private rootedCache?: RootedWalk;
|
|
@@ -618,6 +649,98 @@ export class MemFS implements FileSystem {
|
|
|
618
649
|
if (resolved.node.kind === "dir") return this.pathOf(resolved.node);
|
|
619
650
|
return joinBelow(this.pathOf(resolved.parent!), "/" + resolved.name);
|
|
620
651
|
}
|
|
652
|
+
/** The index of the first of `paths` naming a `kind` node, each walked from `directory` with
|
|
653
|
+
* every link followed, as a stat with the follow flag would; -1 when none does. A path that
|
|
654
|
+
* fails to resolve (missing, ENOTDIR, ELOOP, EACCES, an escape or an absolute path) does not
|
|
655
|
+
* match. Only the start directory can fail the call. */
|
|
656
|
+
probe(directory: FileHandle, paths: readonly string[], kind: ProbeKind, rooted = false): number {
|
|
657
|
+
if (paths.length > PROBE_PATH_LIMIT) throw new FilesystemError(28);
|
|
658
|
+
const start = this.directory(directory);
|
|
659
|
+
const wanted = kind === "directory" ? "dir" : "file";
|
|
660
|
+
for (let index = 0; index < paths.length; index++) {
|
|
661
|
+
const path = paths[index]!;
|
|
662
|
+
if (path.startsWith("/")) continue;
|
|
663
|
+
const resolved = this.walkNodes(start, path, false, true, undefined, rooted);
|
|
664
|
+
if (typeof resolved !== "number" && resolved.node?.kind === wanted) return index;
|
|
665
|
+
if (wanted === "file" && this.matchesVirtualMachineId(start, path, resolved, rooted))
|
|
666
|
+
return index;
|
|
667
|
+
}
|
|
668
|
+
return -1;
|
|
669
|
+
}
|
|
670
|
+
private matchesVirtualMachineId(
|
|
671
|
+
start: DirNode,
|
|
672
|
+
path: string,
|
|
673
|
+
resolved: TreePath | number,
|
|
674
|
+
rooted: boolean,
|
|
675
|
+
): boolean {
|
|
676
|
+
if (typeof resolved !== "number") {
|
|
677
|
+
if (resolved.node !== undefined || resolved.trailingSlash || resolved.name !== "machine-id")
|
|
678
|
+
return false;
|
|
679
|
+
const etc = this.walkNodes(this.root, "etc", false, true, undefined, true);
|
|
680
|
+
return typeof etc !== "number" && etc.node?.kind === "dir" && resolved.parent === etc.node;
|
|
681
|
+
}
|
|
682
|
+
if (resolved !== 44) return false;
|
|
683
|
+
return this.walkSyntheticMachineId(start, path, rooted);
|
|
684
|
+
}
|
|
685
|
+
private walkSyntheticMachineId(start: DirNode, path: string, rooted: boolean): boolean {
|
|
686
|
+
if (path.endsWith("/")) return false;
|
|
687
|
+
let current: DirNode = start;
|
|
688
|
+
let pending = path.split("/");
|
|
689
|
+
let offset = 0;
|
|
690
|
+
let expansions = 0;
|
|
691
|
+
while (offset < pending.length) {
|
|
692
|
+
const part = pending[offset++]!;
|
|
693
|
+
if (!part || part === ".") continue;
|
|
694
|
+
if (!(current.mode & 0o100)) return false;
|
|
695
|
+
if (part === "..") {
|
|
696
|
+
const parent = this.stepParentForProbe(current, start, rooted);
|
|
697
|
+
if (!parent) return false;
|
|
698
|
+
current = parent;
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
const child = current.children.get(part);
|
|
702
|
+
if (!child) return this.isSyntheticMachineIdTail(current, part, pending, offset);
|
|
703
|
+
if (child.kind === "dir") {
|
|
704
|
+
this.directoryParents.set(child, current);
|
|
705
|
+
current = child;
|
|
706
|
+
continue;
|
|
707
|
+
}
|
|
708
|
+
if (child.kind !== "symlink" || ++expansions > 40 || !child.target) return false;
|
|
709
|
+
if (child.target.startsWith("/")) {
|
|
710
|
+
if (!rooted) return false;
|
|
711
|
+
current = this.root;
|
|
712
|
+
}
|
|
713
|
+
pending = child.target.split("/").concat(pending.slice(offset));
|
|
714
|
+
offset = 0;
|
|
715
|
+
}
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
private stepParentForProbe(current: DirNode, start: DirNode, rooted: boolean): DirNode | null {
|
|
719
|
+
if (current === this.root) return rooted ? this.root : null;
|
|
720
|
+
if (!rooted && current === start) return null;
|
|
721
|
+
const parent = this.liveParent(current);
|
|
722
|
+
return typeof parent === "number" ? null : parent;
|
|
723
|
+
}
|
|
724
|
+
private isSyntheticMachineIdTail(
|
|
725
|
+
current: DirNode,
|
|
726
|
+
part: string,
|
|
727
|
+
pending: readonly string[],
|
|
728
|
+
offset: number,
|
|
729
|
+
): boolean {
|
|
730
|
+
if (current !== this.root || part !== "etc") return false;
|
|
731
|
+
let sawMachineId = false;
|
|
732
|
+
for (let i = offset; i < pending.length; i++) {
|
|
733
|
+
const next = pending[i]!;
|
|
734
|
+
if (sawMachineId) return false;
|
|
735
|
+
if (!next || next === ".") continue;
|
|
736
|
+
if (next === "machine-id") {
|
|
737
|
+
sawMachineId = true;
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
return false;
|
|
741
|
+
}
|
|
742
|
+
return sawMachineId;
|
|
743
|
+
}
|
|
621
744
|
/** The absolute path of a live directory, by its parent edges up to the root. */
|
|
622
745
|
private pathOf(dir: DirNode): string | number {
|
|
623
746
|
const names: string[] = [];
|
|
@@ -1315,7 +1438,15 @@ export class MemFS implements FileSystem {
|
|
|
1315
1438
|
}
|
|
1316
1439
|
}
|
|
1317
1440
|
|
|
1318
|
-
|
|
1441
|
+
readonly machineId: string;
|
|
1442
|
+
constructor(
|
|
1443
|
+
public root: DirNode = newDir(),
|
|
1444
|
+
machineId?: string,
|
|
1445
|
+
) {
|
|
1446
|
+
this.machineId =
|
|
1447
|
+
machineId !== undefined
|
|
1448
|
+
? validateMachineId(machineId)
|
|
1449
|
+
: validateMachineId(crypto.randomUUID().replaceAll("-", "").toLowerCase());
|
|
1319
1450
|
adoptInodes(root);
|
|
1320
1451
|
this.changeLinkCount(root, 1);
|
|
1321
1452
|
const pending = [root];
|