- Fixed all of path_resolver.ts functions
- `resolveInode` functions now `resolvePointer` - Fixed all resolve pointer -> path functions
This commit is contained in:
@@ -4,7 +4,7 @@ import { createErrorResult, createSuccessResult, type ResultSuccess } from "@cor
|
|||||||
import { getCurrentSession } from "@core/session_manager";
|
import { getCurrentSession } from "@core/session_manager";
|
||||||
import type { ShellState } from "@core/shell_state";
|
import type { ShellState } from "@core/shell_state";
|
||||||
import type { InvalidArgumentsError, ShellError } from "@core/util/errors";
|
import type { InvalidArgumentsError, ShellError } from "@core/util/errors";
|
||||||
import { resolveInode } from "@core/util/path_resolver";
|
import { resolvePointer } from "@core/util/path_resolver";
|
||||||
|
|
||||||
export const COMMAND_NAME = "pwd";
|
export const COMMAND_NAME = "pwd";
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
|||||||
}
|
}
|
||||||
|
|
||||||
const session = getCurrentSession(state);
|
const session = getCurrentSession(state);
|
||||||
const path = resolveInode(state, session.cwd);
|
const path = resolvePointer(state, session.cwd);
|
||||||
|
|
||||||
io.writeStdout(new TextEncoder().encode(path));
|
io.writeStdout(new TextEncoder().encode(path));
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,6 @@ import { fromPtr, NodeType, toPtr, type Node, type NodePointer } from "@core/fil
|
|||||||
import { getCurrentSession } from "@core/session_manager";
|
import { getCurrentSession } from "@core/session_manager";
|
||||||
import type { ShellState } from "@core/shell_state";
|
import type { ShellState } from "@core/shell_state";
|
||||||
|
|
||||||
/*
|
|
||||||
/home/grzegorz/Documents/homework
|
|
||||||
|
|
||||||
""
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function resolvePath(state: ShellState, path: string): { device_id: number; inode: number } {
|
export function resolvePath(state: ShellState, path: string): { device_id: number; inode: number } {
|
||||||
let linkDepth = 0;
|
let linkDepth = 0;
|
||||||
const maxDepth = state.filesystem.maxSymlinkDepth;
|
const maxDepth = state.filesystem.maxSymlinkDepth;
|
||||||
@@ -198,19 +192,50 @@ export function resolvePath(state: ShellState, path: string): { device_id: numbe
|
|||||||
return { device_id: currentDeviceId, inode: currentNode.inode };
|
return { device_id: currentDeviceId, inode: currentNode.inode };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveInode(state: ShellState, inode: number): string {
|
export function resolvePointer(state: ShellState, pointer: NodePointer): string {
|
||||||
const node = state.filesystem.getNode(inode);
|
const node = state.filesystem.getNode(pointer);
|
||||||
const components: string[] = [];
|
const components: string[] = [];
|
||||||
|
|
||||||
if (node === undefined) return "";
|
if (node === undefined) return "";
|
||||||
|
|
||||||
let currentInode = inode;
|
let ptr = pointer;
|
||||||
while (currentInode !== 0) {
|
// TODO: Change while statements condition to not be hardcoded
|
||||||
const node = state.filesystem.getNode(currentInode) as TreeNode;
|
while (ptr !== "0:0") {
|
||||||
if (!node) break;
|
if (state.filesystem.isMountTarget(ptr)) {
|
||||||
|
const mount = state.filesystem.getMountPoint(ptr);
|
||||||
|
if (!mount) {
|
||||||
|
throw {
|
||||||
|
type: "FileSystemCorruption",
|
||||||
|
message: "Mount registry entry missing, FileSystem corrupted",
|
||||||
|
timestamp: Date.now(),
|
||||||
|
} satisfies FileSystemCorruptionError;
|
||||||
|
}
|
||||||
|
|
||||||
components.push(node.name);
|
const entries = state.filesystem.getNodeEntries(mount);
|
||||||
currentInode = node.parent;
|
if (!entries?.[0]) {
|
||||||
|
throw {
|
||||||
|
type: "FileSystemCorruption",
|
||||||
|
message: "Reverse index entry missing, FileSystem corrupted",
|
||||||
|
timestamp: Date.now(),
|
||||||
|
} satisfies FileSystemCorruptionError;
|
||||||
|
}
|
||||||
|
|
||||||
|
components.push(entries[0].name);
|
||||||
|
ptr = toPtr({ device_id: entries[0].pdevice_id, inode: entries[0].pinode });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entries = state.filesystem.getNodeEntries(ptr);
|
||||||
|
if (!entries?.[0]) {
|
||||||
|
throw {
|
||||||
|
type: "FileSystemCorruption",
|
||||||
|
message: "Reverse index entry missing, FileSystem corrupted",
|
||||||
|
timestamp: Date.now(),
|
||||||
|
} satisfies FileSystemCorruptionError;
|
||||||
|
}
|
||||||
|
|
||||||
|
components.push(entries[0].name);
|
||||||
|
ptr = toPtr({ device_id: entries[0].pdevice_id, inode: entries[0].pinode });
|
||||||
}
|
}
|
||||||
if (components.length === 0) {
|
if (components.length === 0) {
|
||||||
components.push("/");
|
components.push("/");
|
||||||
@@ -223,9 +248,9 @@ export function resolveInode(state: ShellState, inode: number): string {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveInodeToHome(state: ShellState, inode: number): string {
|
export function resolvePointerToHome(state: ShellState, ptr: NodePointer): string {
|
||||||
const home = resolveInode(state, getCurrentSession(state).user.home);
|
const home = resolvePointer(state, getCurrentSession(state).user.home);
|
||||||
let result = resolveInode(state, inode);
|
let result = resolvePointer(state, ptr);
|
||||||
|
|
||||||
if (result.startsWith(home)) {
|
if (result.startsWith(home)) {
|
||||||
result = `~${result.slice(home.length)}`;
|
result = `~${result.slice(home.length)}`;
|
||||||
@@ -234,9 +259,9 @@ export function resolveInodeToHome(state: ShellState, inode: number): string {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveInodeToCwd(state: ShellState, inode: number): string {
|
export function resolvePointerToCwd(state: ShellState, ptr: NodePointer): string {
|
||||||
const cwd = resolveInode(state, getCurrentSession(state).cwd);
|
const cwd = resolvePointer(state, getCurrentSession(state).cwd);
|
||||||
let result = resolveInode(state, inode);
|
let result = resolvePointer(state, ptr);
|
||||||
|
|
||||||
if (result.startsWith(cwd)) {
|
if (result.startsWith(cwd)) {
|
||||||
result = `.${result.slice(cwd.length)}`;
|
result = `.${result.slice(cwd.length)}`;
|
||||||
@@ -245,9 +270,9 @@ export function resolveInodeToCwd(state: ShellState, inode: number): string {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveInodeRelative(state: ShellState, inode: number, relative: number): string {
|
export function resolvePointerRelative(state: ShellState, ptr: NodePointer, relative: NodePointer): string {
|
||||||
const rel = resolveInode(state, relative);
|
const rel = resolvePointer(state, relative);
|
||||||
let result = resolveInode(state, inode);
|
let result = resolvePointer(state, ptr);
|
||||||
|
|
||||||
if (result.startsWith(rel)) {
|
if (result.startsWith(rel)) {
|
||||||
result = `.${result.slice(rel.length)}`;
|
result = `.${result.slice(rel.length)}`;
|
||||||
|
|||||||
+6
-6
@@ -13,12 +13,10 @@ namespace Termos {
|
|||||||
//import { FileSystem } from "@core/filesystem/filesystem";
|
//import { FileSystem } from "@core/filesystem/filesystem";
|
||||||
import { FileSystem } from "@core/filesystem/filesystem";
|
import { FileSystem } from "@core/filesystem/filesystem";
|
||||||
import type { IDataStore, IMetaStore, VDiskConfig } from "@core/filesystem/vdisk";
|
import type { IDataStore, IMetaStore, VDiskConfig } from "@core/filesystem/vdisk";
|
||||||
import type { GroupInfo, UserInfo } from "@core/session_manager";
|
import { getCurrentSession, type GroupInfo, type UserInfo } from "@core/session_manager";
|
||||||
import { createInitialShellState, type ShellState } from "@core/shell_state";
|
import { createInitialShellState, type ShellState } from "@core/shell_state";
|
||||||
|
import { resolvePointer } from "@core/util/path_resolver";
|
||||||
import { MemDataStore, MemMetaStore } from "@core/util/temp_mem_stores";
|
import { MemDataStore, MemMetaStore } from "@core/util/temp_mem_stores";
|
||||||
//import { getCurrentSession, type GroupInfo, type UserInfo } from "@core/session_manager";
|
|
||||||
//import { createInitialShellState, type ShellState } from "@core/shell_state";
|
|
||||||
//import { resolveInodeToHome } from "@core/util/path_resolver";
|
|
||||||
import { deserializeFileSystem } from "@shell/serializer";
|
import { deserializeFileSystem } from "@shell/serializer";
|
||||||
import { Shell } from "@shell/shell";
|
import { Shell } from "@shell/shell";
|
||||||
//import { deserializeFileSystem } from "@shell/serializer";
|
//import { deserializeFileSystem } from "@shell/serializer";
|
||||||
@@ -47,7 +45,7 @@ for (const i of arr) {
|
|||||||
devices.push({ dstore: data, mstore: meta, config });
|
devices.push({ dstore: data, mstore: meta, config });
|
||||||
}
|
}
|
||||||
|
|
||||||
const fs = FileSystem.init(devices);
|
const fs = await FileSystem.init(devices);
|
||||||
|
|
||||||
const users: Map<number, UserInfo> = new Map();
|
const users: Map<number, UserInfo> = new Map();
|
||||||
const groups: Map<number, GroupInfo> = new Map();
|
const groups: Map<number, GroupInfo> = new Map();
|
||||||
@@ -56,7 +54,7 @@ const user: UserInfo = {
|
|||||||
uid: 1000,
|
uid: 1000,
|
||||||
gid: 1000, // <- PRIMARY GID
|
gid: 1000, // <- PRIMARY GID
|
||||||
group: [1000], // <- GROUPS ARRAY
|
group: [1000], // <- GROUPS ARRAY
|
||||||
home: 14,
|
home: "0:14",
|
||||||
};
|
};
|
||||||
const group: GroupInfo = {
|
const group: GroupInfo = {
|
||||||
groupname: "kamil",
|
groupname: "kamil",
|
||||||
@@ -69,6 +67,8 @@ groups.set(1000, group);
|
|||||||
const state: ShellState = createInitialShellState(fs, users, groups, user);
|
const state: ShellState = createInitialShellState(fs, users, groups, user);
|
||||||
Shell.init(state);
|
Shell.init(state);
|
||||||
|
|
||||||
|
console.log(resolvePointer(state, "0:15"));
|
||||||
|
|
||||||
//console.log(resolveInode(Shell.Instance?.State!, 6));
|
//console.log(resolveInode(Shell.Instance?.State!, 6));
|
||||||
//console.log(resolveInode(Shell.Instance?.State!, 6, true));
|
//console.log(resolveInode(Shell.Instance?.State!, 6, true));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user