a lot of mess, keep working on VDisk for now.

This commit is contained in:
2026-09-17 10:32:31 +02:00
parent 9c5bd71a5c
commit 849e0e61f5
20 changed files with 839 additions and 259 deletions
+38 -20
View File
@@ -1,7 +1,7 @@
import { getCurrentSession } from "@core/session_manager";
import type { ShellState } from "@core/shell_state";
import type { NodeNotFoundError, NotADirectoryError } from "../filesystem/errors";
import { TreeNodeType, type DirectoryNode, type TreeNode } from "../filesystem/treenode";
import { TreeNodeType, type DirectoryNode, type NodeEntry, type NodePointer, type TreeNode } from "../filesystem/node";
/*
/home/grzegorz/Documents/homework
@@ -9,29 +9,55 @@ import { TreeNodeType, type DirectoryNode, type TreeNode } from "../filesystem/t
""
*/
export function resolvePath(state: ShellState, path: string): string {
export function resolvePath(state: ShellState, path: string): NodeEntry {
const session = getCurrentSession(state);
const isAbsolute = path.startsWith("/"); // true
const normalizedPath: string = path.replace(/^\/+|\/+$/g, ""); // home/grzegorz/Documents/homework
const pathComponents: string[] = normalizedPath.split("/").filter(name => name.length > 0); // ["home", "grzegorz", "Documents", "homework"]
let currentVD: number = state.filesystem.getSysPartitionID();
// Fix to dynamically get the root inode VV
if (pathComponents.length === 0 && isAbsolute) return 0;
if (pathComponents.length === 0 && isAbsolute) return [0, currentVD];
// Move behaviour into cd built-in
if (pathComponents.length === 0) return session.cwd;
if (pathComponents.length === 0) return [session.cwd, currentVD];
let currentNode =
isAbsolute === true ? state.filesystem.getRoot() : (state.filesystem.getNode(session.cwd) as DirectoryNode);
let currentNode = isAbsolute === true ? state.filesystem.getRoot() : state.filesystem.getNode(session.cwd)!;
if (!currentNode) return -1;
if (!currentNode) {
throw Error("Current working directory does not exist in the filesystem! Is the userdata corrupted?");
}
for (let i = 0; i < pathComponents.length; i++) {
// Null assertion because by this point the array cannot be empty
const name: string = pathComponents[i]!;
if (name === ".") continue;
if (name === "..") {
currentNode = state.filesystem.getNode(currentNode.parent) as DirectoryNode;
if (state.filesystem.isFile(currentNode.inode) && !(i === pathComponents.length - 1))
throw {
type: "NotADirectory",
message: `${name} is not a directory`,
timestamp: Date.now(),
inode: currentNode.inode,
nodeType: TreeNodeType.File,
} satisfies NotADirectoryError;
if (currentNode.type === TreeNodeType.Device) {
currentVD = currentNode.target_id;
continue;
}
if (currentNode.type === TreeNodeType.Symlink) {
const ptr: NodePointer = resolvePath(state, currentNode.target);
currentNode = state.filesystem.getNode(ptr)!;
if (!currentNode) {
throw {
type: "NodeNotFound",
message: `${name} not found`,
timestamp: Date.now(),
inode: ptr[0],
} satisfies NodeNotFoundError;
}
continue;
}
@@ -45,23 +71,15 @@ export function resolvePath(state: ShellState, path: string): string {
if (!inode)
throw {
type: "NodeNotFound",
message: `Child node in ${currentNode.name} under name ${name} not found`,
message: `${name} not found`,
timestamp: Date.now(),
inode: currentNode.inode,
} satisfies NodeNotFoundError;
if (state.filesystem.isFile(inode) && !(i === pathComponents.length - 1))
throw {
type: "NotADirectory",
message: `Child node ${name} is not a directory`,
timestamp: Date.now(),
inode: inode,
nodeType: TreeNodeType.File,
} satisfies NotADirectoryError;
currentNode = state.filesystem.getNode(inode) as DirectoryNode;
}
return currentNode.inode;
return [currentNode.inode, currentVD];
}
export function resolveInode(state: ShellState, inode: number): string {