- fixed a bug in dnTaverseTree where children would get pushed into the result in reverse order
- added an inode display to the `printTree` algorithm - removed a redundant type in *`signal.ts`* - improved `resolveInode` to now take `ShellState` instead of `FileSystem` and added an optional `abs` *`boolean`* argument to determine if the retuned path should be normalized or absolute - implemented a builtin `TreeNode` quicksort function - changed the `TreeNodeType` to a numeric enum - added a standalone `Posix` class that holds a const with character weights compliant with posix
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { getCurrentSession } from "@core/session_manager";
|
||||
import type { ShellState } from "@core/shell_state";
|
||||
import type { NodeNotFoundError, NotADirectoryError } from "../filesystem/errors";
|
||||
import type { FileSystem } from "../filesystem/filesystem";
|
||||
import { TreeNodeType, type DirectoryNode, type TreeNode } from "../filesystem/treenode";
|
||||
@@ -53,15 +55,15 @@ export function resolvePath(fs: FileSystem, cwd: number, path: string): number {
|
||||
return currentNode.inode;
|
||||
}
|
||||
|
||||
export function resolveInode(fs: FileSystem, inode: number): string {
|
||||
const node = fs.getNode(inode);
|
||||
export function resolveInode(state: ShellState, inode: number, abs: boolean = false): string {
|
||||
const node = state.filesystem.getNode(inode);
|
||||
const components: string[] = [];
|
||||
|
||||
if (node === undefined) return "";
|
||||
|
||||
let currentInode = inode;
|
||||
while (currentInode !== 0) {
|
||||
const node = fs.getNode(currentInode) as TreeNode;
|
||||
const node = state.filesystem.getNode(currentInode) as TreeNode;
|
||||
if (!node) break;
|
||||
|
||||
components.push(node.name);
|
||||
@@ -72,7 +74,19 @@ export function resolveInode(fs: FileSystem, inode: number): string {
|
||||
return components.join("");
|
||||
}
|
||||
|
||||
components.reverse();
|
||||
components.unshift("");
|
||||
return components.join("/");
|
||||
components.reverse().unshift("");
|
||||
let result = components.join("/");
|
||||
|
||||
if (abs) return result;
|
||||
|
||||
const home = resolveInode(state, getCurrentSession(state).user.home, true);
|
||||
const cwd = resolveInode(state, getCurrentSession(state).cwd, true);
|
||||
|
||||
if (result.startsWith(home)) {
|
||||
result = `~${result.slice(home.length)}`;
|
||||
} else if (result.startsWith(cwd) && cwd !== "/") {
|
||||
result = `.${result.slice(cwd.length)}`;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user