- Fixed sort.ts
- Fixed `cd`
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import type { FileSystemCorruptionError, NodeNotFoundError, NotADirectoryError } from "@core/filesystem/errors";
|
||||
import { fromPtr, NodeType, toPtr, type Node, type NodePointer } from "@core/filesystem/node";
|
||||
import { NodePointer, NodeType, type Node } from "@core/filesystem/node";
|
||||
import { getCurrentSession } from "@core/session_manager";
|
||||
import type { ShellState } from "@core/shell_state";
|
||||
|
||||
export function resolvePath(state: ShellState, path: string): { device_id: number; inode: number } {
|
||||
export function resolvePath(state: ShellState, path: string): NodePointer {
|
||||
let linkDepth = 0;
|
||||
const maxDepth = state.filesystem.maxSymlinkDepth;
|
||||
|
||||
@@ -19,8 +19,8 @@ export function resolvePath(state: ShellState, path: string): { device_id: numbe
|
||||
currentDeviceId = 0;
|
||||
currentNode = state.filesystem.getRoot();
|
||||
} else if (!isAbsolute && pathComponents[0] === "~") {
|
||||
const home = fromPtr(session.user.home);
|
||||
currentDeviceId = home.device_id;
|
||||
const home = session.user.home;
|
||||
currentDeviceId = home.device;
|
||||
currentNode = state.filesystem.getNode(session.user.home)!;
|
||||
if (!currentNode) {
|
||||
throw {
|
||||
@@ -48,16 +48,13 @@ export function resolvePath(state: ShellState, path: string): { device_id: numbe
|
||||
} satisfies FileSystemCorruptionError;
|
||||
}
|
||||
currentDeviceId = entries[0].pdevice_id;
|
||||
currentNode = state.filesystem.getNode(
|
||||
toPtr({ device_id: entries[0].pdevice_id, inode: entries[0].pinode }),
|
||||
)!;
|
||||
currentNode = state.filesystem.getNode(NodePointer.of(entries[0].pdevice_id, entries[0].pinode))!;
|
||||
}
|
||||
|
||||
pathComponents.unshift(...target.split("/").filter(c => c.length > 0));
|
||||
}
|
||||
} else {
|
||||
const cwd = fromPtr(session.cwd);
|
||||
currentDeviceId = cwd.device_id;
|
||||
currentDeviceId = session.cwd.device;
|
||||
currentNode = state.filesystem.getNode(session.cwd)!;
|
||||
if (!currentNode) {
|
||||
throw {
|
||||
@@ -74,10 +71,8 @@ export function resolvePath(state: ShellState, path: string): { device_id: numbe
|
||||
|
||||
if (name === ".") continue;
|
||||
if (name === "..") {
|
||||
if (state.filesystem.isMountTarget(toPtr({ device_id: currentDeviceId, inode: currentNode.inode }))) {
|
||||
const mount = state.filesystem.getMountPoint(
|
||||
toPtr({ device_id: currentDeviceId, inode: currentNode.inode }),
|
||||
);
|
||||
if (state.filesystem.isMountTarget(NodePointer.of(currentDeviceId, currentNode.inode))) {
|
||||
const mount = state.filesystem.getMountPoint(NodePointer.of(currentDeviceId, currentNode.inode));
|
||||
if (!mount) {
|
||||
throw {
|
||||
type: "FileSystemCorruption",
|
||||
@@ -96,16 +91,12 @@ export function resolvePath(state: ShellState, path: string): { device_id: numbe
|
||||
}
|
||||
|
||||
currentDeviceId = entries[0].pdevice_id;
|
||||
currentNode = state.filesystem.getNode(
|
||||
toPtr({ device_id: entries[0].pdevice_id, inode: entries[0].pinode }),
|
||||
)!;
|
||||
currentNode = state.filesystem.getNode(NodePointer.of(entries[0].pdevice_id, entries[0].pinode))!;
|
||||
continue;
|
||||
}
|
||||
if (currentNode.inode === 0) continue;
|
||||
|
||||
const entries = state.filesystem.getNodeEntries(
|
||||
toPtr({ device_id: currentDeviceId, inode: currentNode.inode }),
|
||||
);
|
||||
const entries = state.filesystem.getNodeEntries(NodePointer.of(currentDeviceId, currentNode.inode));
|
||||
|
||||
if (!entries?.[0]) {
|
||||
throw {
|
||||
@@ -116,9 +107,7 @@ export function resolvePath(state: ShellState, path: string): { device_id: numbe
|
||||
}
|
||||
|
||||
currentDeviceId = entries[0].pdevice_id;
|
||||
currentNode = state.filesystem.getNode(
|
||||
toPtr({ device_id: entries[0].pdevice_id, inode: entries[0].pinode }),
|
||||
)!;
|
||||
currentNode = state.filesystem.getNode(NodePointer.of(entries[0].pdevice_id, entries[0].pinode))!;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -138,16 +127,16 @@ export function resolvePath(state: ShellState, path: string): { device_id: numbe
|
||||
type: "NodeNotFound",
|
||||
message: `${name} not found`,
|
||||
timestamp: Date.now(),
|
||||
pointer: toPtr({ device_id: currentDeviceId, inode: currentNode.inode }),
|
||||
pointer: NodePointer.of(currentDeviceId, currentNode.inode),
|
||||
} satisfies NodeNotFoundError;
|
||||
}
|
||||
|
||||
let childPtr = toPtr({ device_id: currentDeviceId, inode: childInode });
|
||||
let childPtr = NodePointer.of(currentDeviceId, currentNode.inode);
|
||||
|
||||
if (state.filesystem.isMountPoint(childPtr)) {
|
||||
const mount = state.filesystem.getMountTarget(childPtr)!.split("-")[0] as NodePointer;
|
||||
const mount = state.filesystem.getMountTarget(childPtr)!;
|
||||
childPtr = mount;
|
||||
currentDeviceId = fromPtr(mount).device_id;
|
||||
currentDeviceId = mount.device;
|
||||
}
|
||||
|
||||
let child = state.filesystem.getNode(childPtr);
|
||||
@@ -177,9 +166,7 @@ export function resolvePath(state: ShellState, path: string): { device_id: numbe
|
||||
} satisfies FileSystemCorruptionError;
|
||||
}
|
||||
currentDeviceId = entries[0].pdevice_id;
|
||||
currentNode = state.filesystem.getNode(
|
||||
toPtr({ device_id: entries[0].pdevice_id, inode: entries[0].pinode }),
|
||||
)!;
|
||||
currentNode = state.filesystem.getNode(NodePointer.of(entries[0].pdevice_id, entries[0].pinode))!;
|
||||
}
|
||||
|
||||
pathComponents.unshift(...target.split("/").filter(c => c.length > 0));
|
||||
@@ -189,7 +176,7 @@ export function resolvePath(state: ShellState, path: string): { device_id: numbe
|
||||
currentNode = child;
|
||||
}
|
||||
|
||||
return { device_id: currentDeviceId, inode: currentNode.inode };
|
||||
return NodePointer.of(currentDeviceId, currentNode.inode);
|
||||
}
|
||||
|
||||
export function resolvePointer(state: ShellState, pointer: NodePointer): string {
|
||||
@@ -200,7 +187,7 @@ export function resolvePointer(state: ShellState, pointer: NodePointer): string
|
||||
|
||||
let ptr = pointer;
|
||||
// TODO: Change while statements condition to not be hardcoded
|
||||
while (ptr !== "0:0") {
|
||||
while (ptr.equals(NodePointer.of(0, 0))) {
|
||||
if (state.filesystem.isMountTarget(ptr)) {
|
||||
const mount = state.filesystem.getMountPoint(ptr);
|
||||
if (!mount) {
|
||||
@@ -221,7 +208,7 @@ export function resolvePointer(state: ShellState, pointer: NodePointer): string
|
||||
}
|
||||
|
||||
components.push(entries[0].name);
|
||||
ptr = toPtr({ device_id: entries[0].pdevice_id, inode: entries[0].pinode });
|
||||
ptr = NodePointer.of(entries[0].pdevice_id, entries[0].pinode);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -235,7 +222,7 @@ export function resolvePointer(state: ShellState, pointer: NodePointer): string
|
||||
}
|
||||
|
||||
components.push(entries[0].name);
|
||||
ptr = toPtr({ device_id: entries[0].pdevice_id, inode: entries[0].pinode });
|
||||
ptr = NodePointer.of(entries[0].pdevice_id, entries[0].pinode);
|
||||
}
|
||||
if (components.length === 0) {
|
||||
components.push("/");
|
||||
|
||||
Reference in New Issue
Block a user