- Fixed sort.ts
- Fixed `cd`
This commit is contained in:
+10
-8
@@ -1,5 +1,6 @@
|
||||
import type { CommandDescriptor, CommandOutput } from "@core/command";
|
||||
import type { CommandIO } from "@core/command_io";
|
||||
import type { NodePointer } from "@core/filesystem/node";
|
||||
import { createErrorResult, createSuccessResult } from "@core/result";
|
||||
import { getCurrentSession } from "@core/session_manager";
|
||||
import { ShellState, withCwd } from "@core/shell_state";
|
||||
@@ -26,16 +27,17 @@ async function main(__io: CommandIO, state: ShellState, args: string[]): Promise
|
||||
} satisfies CommandOutput<InvalidArgumentsError>;
|
||||
}
|
||||
|
||||
let inode: number;
|
||||
let ptr: NodePointer;
|
||||
const session = getCurrentSession(state);
|
||||
|
||||
if (args[0] === undefined) {
|
||||
inode = session.user.home;
|
||||
ptr = session.user.home;
|
||||
} else if (args[0] === "-") {
|
||||
inode = session.pwd;
|
||||
ptr = session.pwd;
|
||||
} else {
|
||||
inode = resolvePath(state, args[0]);
|
||||
if (inode === -1) {
|
||||
try {
|
||||
ptr = resolvePath(state, args[0]);
|
||||
} catch (e) {
|
||||
return {
|
||||
state,
|
||||
result: createErrorResult(
|
||||
@@ -48,21 +50,21 @@ async function main(__io: CommandIO, state: ShellState, args: string[]): Promise
|
||||
}
|
||||
}
|
||||
|
||||
if (state.filesystem.isFile(inode)) {
|
||||
if (state.filesystem.isFile(ptr)) {
|
||||
return {
|
||||
state,
|
||||
result: createErrorResult("PathResolutionError", "Not a directory", { path: args[0]! }, COMMAND_NAME),
|
||||
} satisfies CommandOutput<PathResolutionError>;
|
||||
}
|
||||
|
||||
if (!state.filesystem.canExecute(inode, session.user)) {
|
||||
if (!state.filesystem.canExecute(ptr, session.user)) {
|
||||
return {
|
||||
state,
|
||||
result: createErrorResult("PermissionDenied", "Permission denied", { resource: args[0]! }, COMMAND_NAME),
|
||||
} satisfies CommandOutput<PermissionDeniedError>;
|
||||
}
|
||||
|
||||
const returnState = withCwd(state, inode);
|
||||
const returnState = withCwd(state, ptr);
|
||||
|
||||
return {
|
||||
state: returnState,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { CommandDescriptor, CommandOutput } from "@core/command";
|
||||
import type { CommandIO } from "@core/command_io";
|
||||
import { type DirectoryNode } from "@core/filesystem/node";
|
||||
import { type DirectoryNode, type NodePointer } from "@core/filesystem/node";
|
||||
import { createErrorResult, createSuccessResult } from "@core/result";
|
||||
import { getCurrentSession } from "@core/session_manager";
|
||||
import type { ShellState } from "@core/shell_state";
|
||||
@@ -13,7 +13,7 @@ import { convertToUnit } from "@termos/util/format_unit";
|
||||
export const COMMAND_NAME = "ls";
|
||||
|
||||
async function main(io: CommandIO, state: ShellState, args: string[]): Promise<CommandOutput<ShellError>> {
|
||||
const entries: { inode: number; path: string }[] = [];
|
||||
const entries: { ptr: NodePointer; path: string }[] = [];
|
||||
const paths: string[] = [];
|
||||
const e = new TextEncoder();
|
||||
|
||||
@@ -211,11 +211,11 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
const session = getCurrentSession(state);
|
||||
|
||||
if (paths.length === 0) {
|
||||
entries.push({ inode: session.cwd, path: "." });
|
||||
entries.push({ ptr: session.cwd, path: "." });
|
||||
} else {
|
||||
for (const path of paths) {
|
||||
const inode = resolvePath(state, path);
|
||||
if (inode === -1) {
|
||||
const ptr = resolvePath(state, path);
|
||||
if (!state.filesystem.exists(ptr)) {
|
||||
return {
|
||||
state,
|
||||
result: createErrorResult(
|
||||
@@ -226,7 +226,7 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
),
|
||||
};
|
||||
}
|
||||
entries.push({ inode: inode, path });
|
||||
entries.push({ ptr, path });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,8 +246,8 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
result: createSuccessResult(COMMAND_NAME),
|
||||
};
|
||||
|
||||
function listDirEntries(entry: { inode: number; path: string }): void {
|
||||
const node = state.filesystem.getNode(entry.inode) as DirectoryNode;
|
||||
function listDirEntries(entry: { ptr: NodePointer; path: string }): void {
|
||||
const node = state.filesystem.getNode(entry.ptr) as DirectoryNode;
|
||||
|
||||
if (options.recursive) io.writeStdout(e.encode(`${entry.path}:\n`));
|
||||
io.writeStdout(e.encode(`total ${Object.entries(node.children).length}\n`));
|
||||
|
||||
@@ -3,7 +3,40 @@ export type Node = FileNode | DirectoryNode | SymlinkNode;
|
||||
export type NodeHash = ReadonlyMap<number, Node>;
|
||||
export type ShadowHash = ReadonlyMap<number, Node | null>;
|
||||
|
||||
export type NodePointer = `${string}:${string}`;
|
||||
export class NodePointer {
|
||||
private readonly _device_id: number;
|
||||
private readonly _inode: number;
|
||||
|
||||
private constructor(device_id: number, inode: number) {
|
||||
this._device_id = device_id;
|
||||
this._inode = inode;
|
||||
}
|
||||
|
||||
static of(device_id: number, inode: number): NodePointer {
|
||||
return new NodePointer(device_id, inode);
|
||||
}
|
||||
|
||||
static parse(s: string): NodePointer {
|
||||
const m = /^(\d+):(\d+)$/.exec(s);
|
||||
if (!m) throw new Error(`Invalid NodePointer: ${s}`);
|
||||
return new NodePointer(Number(m[1]), Number(m[2]));
|
||||
}
|
||||
|
||||
get device(): number {
|
||||
return this._device_id;
|
||||
}
|
||||
get inode(): number {
|
||||
return this._inode;
|
||||
}
|
||||
toString(): string {
|
||||
return `${this._device_id}:${this.inode}`;
|
||||
}
|
||||
equals(other: NodePointer): boolean {
|
||||
return this._device_id === other._device_id && this.inode === other.inode;
|
||||
}
|
||||
}
|
||||
|
||||
//export type NodePointer = `${string}:${string}`;
|
||||
|
||||
export interface NodeEntry {
|
||||
readonly pinode: number;
|
||||
@@ -57,7 +90,7 @@ export enum NodeType {
|
||||
Symlink = 2,
|
||||
}
|
||||
|
||||
export function toPtr({ device_id, inode }: { device_id: number; inode: number }): NodePointer {
|
||||
/* export function toPtr({ device_id, inode }: { device_id: number; inode: number }): NodePointer {
|
||||
return `${device_id}:${inode}`;
|
||||
}
|
||||
|
||||
@@ -71,4 +104,4 @@ export function fromPtr(ptr: NodePointer): { device_id: number; inode: number }
|
||||
device_id: Number(arr[0]),
|
||||
inode: Number(arr[1]),
|
||||
};
|
||||
}
|
||||
} */
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { FileSystem } from "./filesystem/filesystem";
|
||||
import type { NodePointer } from "./filesystem/node";
|
||||
import { addHistoryEntry } from "./history_state";
|
||||
import type { GroupInfo, UserInfo } from "./session_manager";
|
||||
import { createInitialSessionState, getCurrentSession, type SessionState } from "./session_manager";
|
||||
@@ -38,14 +39,14 @@ export function createShellState(
|
||||
});
|
||||
}
|
||||
|
||||
export function withCwd(state: ShellState, inode: number): ShellState {
|
||||
export function withCwd(state: ShellState, ptr: NodePointer): ShellState {
|
||||
const session = getCurrentSession(state);
|
||||
|
||||
const newSession = Object.freeze({
|
||||
user: session.user,
|
||||
envVars: Object.freeze(session.envVars),
|
||||
history: Object.freeze(session.history),
|
||||
cwd: inode,
|
||||
cwd: ptr,
|
||||
pwd: session.cwd,
|
||||
exitCode: session.exitCode,
|
||||
} satisfies SessionState);
|
||||
|
||||
@@ -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("/");
|
||||
|
||||
+78
-38
@@ -1,8 +1,9 @@
|
||||
import type { FileNode, TreeNode } from "@core/filesystem/node";
|
||||
import type { FileSystemCorruptionError } from "@core/filesystem/errors";
|
||||
import { FileNode, NodePointer } from "@core/filesystem/node";
|
||||
import type { ShellState } from "@core/shell_state";
|
||||
import { Posix } from "@termos/util/posix";
|
||||
|
||||
export enum SortTreeNodeBy {
|
||||
export enum SortNodeBy {
|
||||
NAME = "name",
|
||||
INODE = "inode",
|
||||
SIZE = "size",
|
||||
@@ -13,50 +14,63 @@ export enum SortTreeNodeBy {
|
||||
CTIME = "ctime",
|
||||
}
|
||||
|
||||
export function sortTreeNodes<T extends TreeNode | number>(
|
||||
export function sortNodes(
|
||||
state: ShellState,
|
||||
arr: T[],
|
||||
arr: NodePointer[],
|
||||
r: boolean = false,
|
||||
by: SortTreeNodeBy = SortTreeNodeBy.NAME,
|
||||
): T[] {
|
||||
by: SortNodeBy = SortNodeBy.NAME,
|
||||
): NodePointer[] {
|
||||
if (arr.length === 0) return [];
|
||||
|
||||
const nodes: TreeNode[] = [];
|
||||
/* const nodes: NodePointer[] = [];
|
||||
|
||||
if (typeof arr[0] === "number") {
|
||||
for (const e of arr as number[]) {
|
||||
if (arr[0] instanceof NodePointer) {
|
||||
nodes.push(...(arr as NodePointer[]));
|
||||
for (const e of arr as NodePointer[]) {
|
||||
const node = state.filesystem.getNode(e);
|
||||
if (!node) continue;
|
||||
|
||||
nodes.push(node);
|
||||
}
|
||||
} else {
|
||||
nodes.push(...(arr as TreeNode[]));
|
||||
for (const e of arr as Node[]) {
|
||||
const ptr = NodePointer.of(device, e.inode);
|
||||
nodes.push(ptr);
|
||||
}
|
||||
}
|
||||
*/
|
||||
nodeQS(arr, r, by, 0, arr.length - 1, state);
|
||||
|
||||
nodeQS(nodes, r, by, 0, nodes.length - 1);
|
||||
return arr;
|
||||
|
||||
if (typeof arr[0] === "number") {
|
||||
return nodes.map(n => n.inode) as T[];
|
||||
/* if (arr[0] instanceof NodePointer) {
|
||||
return nodes.map(n => state.filesystem.getNode(n as NodePointer)) as T[];
|
||||
} else {
|
||||
return nodes as T[];
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
function nodeQS(arr: TreeNode[], r: boolean, by: SortTreeNodeBy, start: number, end: number): void {
|
||||
function nodeQS(arr: NodePointer[], r: boolean, by: SortNodeBy, start: number, end: number, state: ShellState): void {
|
||||
if (end <= start) return;
|
||||
|
||||
const pivot = partitionNodeArray(arr, r, by, start, end);
|
||||
nodeQS(arr, r, by, start, pivot - 1);
|
||||
nodeQS(arr, r, by, pivot + 1, end);
|
||||
const pivot = partitionNodeArray(arr, r, by, start, end, state);
|
||||
nodeQS(arr, r, by, start, pivot - 1, state);
|
||||
nodeQS(arr, r, by, pivot + 1, end, state);
|
||||
}
|
||||
|
||||
function partitionNodeArray(part: TreeNode[], r: boolean, by: SortTreeNodeBy, start: number, end: number): number {
|
||||
function partitionNodeArray(
|
||||
part: NodePointer[],
|
||||
r: boolean,
|
||||
by: SortNodeBy,
|
||||
start: number,
|
||||
end: number,
|
||||
state: ShellState,
|
||||
): number {
|
||||
const pivot = part[end];
|
||||
let i = start - 1;
|
||||
|
||||
for (let j = start; j <= end; j++) {
|
||||
if (compareTreeNode(part[j]!, pivot!, by, r) < 0) {
|
||||
if (compareNode(part[j]!, pivot!, by, r, state) < 0) {
|
||||
i++;
|
||||
const temp = part[i]!;
|
||||
part[i] = part[j]!;
|
||||
@@ -72,11 +86,21 @@ function partitionNodeArray(part: TreeNode[], r: boolean, by: SortTreeNodeBy, st
|
||||
return i;
|
||||
}
|
||||
|
||||
function compareTreeNode(a: TreeNode, b: TreeNode, by: SortTreeNodeBy, r: boolean): number {
|
||||
function compareNode(a: NodePointer, b: NodePointer, by: SortNodeBy, r: boolean, state: ShellState): number {
|
||||
switch (by) {
|
||||
case SortTreeNodeBy.NAME: {
|
||||
const A: string = a.name.startsWith(".") ? a.name.slice(1) : a.name;
|
||||
const B: string = b.name.startsWith(".") ? b.name.slice(1) : b.name;
|
||||
case SortNodeBy.NAME: {
|
||||
const entriesA = state.filesystem.getNodeEntries(a);
|
||||
const entriesB = state.filesystem.getNodeEntries(b);
|
||||
if (!entriesA || !entriesB) {
|
||||
throw {
|
||||
type: "FileSystemCorruption",
|
||||
message: "Reverse index entry missing, FileSystem corrupted",
|
||||
timestamp: Date.now(),
|
||||
} satisfies FileSystemCorruptionError;
|
||||
}
|
||||
|
||||
const A: string = entriesA[0]!.name;
|
||||
const B: string = entriesB[0]!.name;
|
||||
const min = Math.min(A.length, B.length);
|
||||
|
||||
for (let i = 0; i < min; i++) {
|
||||
@@ -91,25 +115,39 @@ function compareTreeNode(a: TreeNode, b: TreeNode, by: SortTreeNodeBy, r: boolea
|
||||
return r ? B.length - A.length : A.length - B.length;
|
||||
}
|
||||
|
||||
case SortTreeNodeBy.MTIME:
|
||||
case SortTreeNodeBy.ATIME:
|
||||
case SortTreeNodeBy.CTIME: {
|
||||
const A: number = a[by];
|
||||
const B: number = b[by];
|
||||
case SortNodeBy.MTIME:
|
||||
case SortNodeBy.ATIME:
|
||||
case SortNodeBy.CTIME: {
|
||||
const nodeA = state.filesystem.getNode(a)!;
|
||||
const nodeB = state.filesystem.getNode(a)!;
|
||||
const A: number = nodeA[by];
|
||||
const B: number = nodeB[by];
|
||||
|
||||
return r ? A - B : B - A;
|
||||
}
|
||||
|
||||
case SortTreeNodeBy.SIZE: {
|
||||
const A: number = (a as FileNode).content.byteSize();
|
||||
const B: number = (b as FileNode).content.byteSize();
|
||||
case SortNodeBy.SIZE: {
|
||||
const nodeA = state.filesystem.getNode(a)!;
|
||||
const nodeB = state.filesystem.getNode(a)!;
|
||||
const A: number = (nodeA as FileNode).size;
|
||||
const B: number = (nodeB as FileNode).size;
|
||||
|
||||
return r ? A - B : B - A;
|
||||
}
|
||||
|
||||
case SortTreeNodeBy.EXTENSION: {
|
||||
const A: string = a.name.split(".").pop() ?? "";
|
||||
const B: string = b.name.split(".").pop() ?? "";
|
||||
case SortNodeBy.EXTENSION: {
|
||||
const entriesA = state.filesystem.getNodeEntries(a);
|
||||
const entriesB = state.filesystem.getNodeEntries(b);
|
||||
if (!entriesA || !entriesB) {
|
||||
throw {
|
||||
type: "FileSystemCorruption",
|
||||
message: "Reverse index entry missing, FileSystem corrupted",
|
||||
timestamp: Date.now(),
|
||||
} satisfies FileSystemCorruptionError;
|
||||
}
|
||||
|
||||
const A: string = entriesA[0]!.name.split(".").pop() ?? "";
|
||||
const B: string = entriesB[0]!.name.split(".").pop() ?? "";
|
||||
const min = Math.min(A.length, B.length);
|
||||
|
||||
for (let i = 0; i < min; i++) {
|
||||
@@ -124,12 +162,14 @@ function compareTreeNode(a: TreeNode, b: TreeNode, by: SortTreeNodeBy, r: boolea
|
||||
return r ? B.length - A.length : A.length - B.length;
|
||||
}
|
||||
|
||||
case SortTreeNodeBy.INODE: {
|
||||
case SortNodeBy.INODE: {
|
||||
return r ? a.inode - b.inode : b.inode - a.inode;
|
||||
}
|
||||
|
||||
case SortTreeNodeBy.TYPE: {
|
||||
return r ? b.type - a.type : a.type - b.type;
|
||||
case SortNodeBy.TYPE: {
|
||||
const nodeA = state.filesystem.getNode(a)!;
|
||||
const nodeB = state.filesystem.getNode(a)!;
|
||||
return r ? nodeB.type - nodeA.type : nodeA.type - nodeB.type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-6
@@ -12,10 +12,11 @@ namespace Termos {
|
||||
|
||||
//import { FileSystem } from "@core/filesystem/filesystem";
|
||||
import { FileSystem } from "@core/filesystem/filesystem";
|
||||
import { NodePointer } from "@core/filesystem/node";
|
||||
import type { IDataStore, IMetaStore, VDiskConfig } from "@core/filesystem/vdisk";
|
||||
import { getCurrentSession, type GroupInfo, type UserInfo } from "@core/session_manager";
|
||||
import { createInitialShellState, type ShellState } from "@core/shell_state";
|
||||
import { resolvePointer } from "@core/util/path_resolver";
|
||||
import { resolvePointerToHome } from "@core/util/path_resolver";
|
||||
import { MemDataStore, MemMetaStore } from "@core/util/temp_mem_stores";
|
||||
import { deserializeFileSystem } from "@shell/serializer";
|
||||
import { Shell } from "@shell/shell";
|
||||
@@ -54,7 +55,7 @@ const user: UserInfo = {
|
||||
uid: 1000,
|
||||
gid: 1000, // <- PRIMARY GID
|
||||
group: [1000], // <- GROUPS ARRAY
|
||||
home: "0:14",
|
||||
home: NodePointer.of(0, 14),
|
||||
};
|
||||
const group: GroupInfo = {
|
||||
groupname: "kamil",
|
||||
@@ -67,8 +68,6 @@ groups.set(1000, group);
|
||||
const state: ShellState = createInitialShellState(fs, users, groups, user);
|
||||
Shell.init(state);
|
||||
|
||||
console.log(resolvePointer(state, "0:15"));
|
||||
|
||||
//console.log(resolveInode(Shell.Instance?.State!, 6));
|
||||
//console.log(resolveInode(Shell.Instance?.State!, 6, true));
|
||||
|
||||
@@ -80,7 +79,7 @@ Shell.Instance().on("result", payload => {
|
||||
console.log(payload.result.error.message + "\n");
|
||||
}
|
||||
//process.stdout.write(decoded + "\n");
|
||||
process.stdout.write("\n" + resolveInodeToHome(payload.state, getCurrentSession(payload.state).cwd) + "\n> ");
|
||||
process.stdout.write("\n" + resolvePointerToHome(payload.state, getCurrentSession(payload.state).cwd) + "\n> ");
|
||||
});
|
||||
|
||||
/*
|
||||
@@ -95,7 +94,7 @@ Shell.Instance().on("stdout", payload => {
|
||||
});
|
||||
|
||||
console.clear();
|
||||
process.stdout.write(resolveInodeToHome(state, getCurrentSession(state).cwd) + "\n> ");
|
||||
process.stdout.write(resolvePointerToHome(state, getCurrentSession(state).cwd) + "\n> ");
|
||||
process.stdin.on("data", async data => {
|
||||
if (Shell.Instance().BoundPID !== null) {
|
||||
Shell.Instance().sendInput(data.toString().trim());
|
||||
|
||||
Reference in New Issue
Block a user