- Fixed resolvePath

- Added symlink resolution
- Added mount resolution
- Fixed filesystem not awaiting for disks to be mounted
(now `FileSystem.init()` needs to be called with `await`)
- Removed old test fixture files
- Added a feature-full `resolvePath`test suite

*all tests passing green*
This commit is contained in:
2026-11-10 08:04:57 +01:00
parent dd804f6f14
commit 4fa284de13
14 changed files with 4608 additions and 657 deletions
+32 -23
View File
@@ -1,58 +1,67 @@
import type { FileSystem } from "@core/filesystem/filesystem";
import { TreeNodeType } from "@core/filesystem/node";
import { fromPtr, NodeType, toPtr, type NodePointer, type SymlinkNode } from "@core/filesystem/node";
export function printTree(fs: FileSystem, root: number): string {
export function printTree(fs: FileSystem, root: NodePointer, rootLabel = "/"): string {
const rootNode = fs.getNode(root);
if (rootNode === undefined) return "";
const lines: string[] = [];
lines.push(rootNode.name + ` (${rootNode.inode})`);
const rootFptr = fromPtr(root);
lines.push(`${rootLabel} (${rootFptr.device_id}:${rootFptr.inode})`);
type Frame = {
inode: number;
ptr: NodePointer;
name: string;
prefix: string;
isLast: boolean;
};
const stack: Frame[] = [];
const getSorterChildren = (inode: number): number[] => {
const node = fs.getNode(inode);
if (!node || node.type !== TreeNodeType.Directory) return [];
const getSortedChildren = (ptr: NodePointer): Array<{ name: string; ptr: NodePointer }> => {
const node = fs.getNode(ptr);
if (!node || node.type !== NodeType.Directory) return [];
const entries = Object.entries(node.children);
const { device_id } = fromPtr(ptr);
const entries = Array.from(node.children.entries());
entries.sort(([a], [b]) => a.localeCompare(b));
return entries.map(([, childInode]) => childInode) as number[];
return entries.map(([name, inode]) => ({
name,
ptr: toPtr({ device_id, inode }),
}));
};
const rootChildren = getSorterChildren(root);
const rootChildren = getSortedChildren(root);
for (let i = rootChildren.length - 1; i >= 0; i--) {
const childInode: number = rootChildren[i] as number;
const child = rootChildren[i]!;
const isLast = i === rootChildren.length - 1;
stack.push({ inode: childInode, prefix: "", isLast });
stack.push({ ptr: child.ptr, name: child.name, prefix: "", isLast });
}
while (stack.length > 0) {
const frame = stack.pop()!;
const node = fs.getNode(frame.inode);
const node = fs.getNode(frame.ptr);
if (!node) continue;
const name = node.name;
const fptr = fromPtr(frame.ptr);
const connector = frame.isLast ? "└── " : "├── ";
lines.push(frame.prefix + connector + name + ` (${node.inode})`);
const symlinkSuffix = node.type === NodeType.Symlink ? ` -> ${(node as SymlinkNode).target}` : "";
lines.push(`${frame.prefix}${connector}${frame.name} (${fptr.device_id}:${fptr.inode})${symlinkSuffix}`);
if (node.type === TreeNodeType.Directory) {
if (node.type === NodeType.Directory) {
const childPrefix = frame.prefix + (frame.isLast ? " " : "│ ");
const children = getSorterChildren(frame.inode);
const children = getSortedChildren(frame.ptr);
for (let i = children.length - 1; i >= 0; i--) {
const childInode = children[i] as number;
const child = children[i]!;
const childIsLast = i === children.length - 1;
stack.push({ inode: childInode, prefix: childPrefix, isLast: childIsLast });
stack.push({
ptr: child.ptr,
name: child.name,
prefix: childPrefix,
isLast: childIsLast,
});
}
}
}