- cat added
- touch beginnings - path resolver now returns a -1 on error - added a command template file for easier copy-pasting
This commit is contained in:
@@ -16,16 +16,11 @@ export function resolvePath(state: ShellState, path: string): number {
|
||||
let currentNode = isAbsolute
|
||||
? state.filesystem.getRoot()
|
||||
: (state.filesystem.getNode(session.cwd) as DirectoryNode);
|
||||
if (!currentNode) {
|
||||
throw {
|
||||
type: "NodeNotFound",
|
||||
message: `CWD node under inode ${session.cwd} not found`,
|
||||
timestamp: Date.now(),
|
||||
inode: session.cwd,
|
||||
} satisfies NodeNotFoundError;
|
||||
}
|
||||
|
||||
for (const name of pathComponents) {
|
||||
if (!currentNode) return -1;
|
||||
|
||||
for (let i = 0; i < pathComponents.length; i++) {
|
||||
const name = pathComponents[i]!;
|
||||
if (name === ".") continue;
|
||||
|
||||
if (name === "..") {
|
||||
@@ -42,7 +37,7 @@ export function resolvePath(state: ShellState, path: string): number {
|
||||
timestamp: Date.now(),
|
||||
inode: currentNode.inode,
|
||||
} satisfies NodeNotFoundError;
|
||||
if (state.filesystem.isFile(inode))
|
||||
if (state.filesystem.isFile(inode) && !(i === pathComponents.length - 1))
|
||||
throw {
|
||||
type: "NotADirectory",
|
||||
message: `Child node ${name} is not a directory`,
|
||||
|
||||
Reference in New Issue
Block a user