some bs work, not finished (reference notes board on email for info)
This commit is contained in:
@@ -3,24 +3,31 @@ import type { ShellState } from "@core/shell_state";
|
||||
import type { NodeNotFoundError, NotADirectoryError } from "../filesystem/errors";
|
||||
import { TreeNodeType, type DirectoryNode, type TreeNode } from "../filesystem/treenode";
|
||||
|
||||
/*
|
||||
/home/grzegorz/Documents/homework
|
||||
|
||||
""
|
||||
*/
|
||||
|
||||
export function resolvePath(state: ShellState, path: string): number {
|
||||
const session = getCurrentSession(state);
|
||||
const isAbsolute = path.startsWith("/");
|
||||
const isAbsolute = path.startsWith("/"); // true
|
||||
|
||||
const normalizedPath: string = path.replace(/^\/+|\/+$/g, "");
|
||||
const pathComponents: string[] = normalizedPath.split("/").filter(name => name.length > 0);
|
||||
const normalizedPath: string = path.replace(/^\/+|\/+$/g, ""); // home/grzegorz/Documents/homework
|
||||
const pathComponents: string[] = normalizedPath.split("/").filter(name => name.length > 0); // ["home", "grzegorz", "Documents", "homework"]
|
||||
|
||||
// Fix to dynamically get the root inode VV
|
||||
if (pathComponents.length === 0 && isAbsolute) return 0;
|
||||
// Move behaviour into cd built-in
|
||||
if (pathComponents.length === 0) return session.cwd;
|
||||
|
||||
let currentNode = isAbsolute
|
||||
? state.filesystem.getRoot()
|
||||
: (state.filesystem.getNode(session.cwd) as DirectoryNode);
|
||||
let currentNode =
|
||||
isAbsolute === true ? state.filesystem.getRoot() : (state.filesystem.getNode(session.cwd) as DirectoryNode);
|
||||
|
||||
if (!currentNode) return -1;
|
||||
|
||||
for (let i = 0; i < pathComponents.length; i++) {
|
||||
const name = pathComponents[i]!;
|
||||
const name: string = pathComponents[i]!;
|
||||
if (name === ".") continue;
|
||||
|
||||
if (name === "..") {
|
||||
|
||||
Reference in New Issue
Block a user