Fixed FS class logic, with full support for table fs structure. Terminal sucressfully initializes (havent checked the commands) ls broken.

This commit is contained in:
2025-12-03 08:40:40 +01:00
parent 8e0ae3dd83
commit d404f5daab
8 changed files with 130 additions and 75 deletions

View File

@@ -129,9 +129,9 @@ export class Bash {
}
}
private appendNewResult(path: string[], output: any, cmd: string) {
private appendNewResult(workingDir: number, output: any, cmd: string) {
const data: PrintData = {
path: this.vfs.formatPath(this.vfs.pathArrayToString(path)),
path: this.vfs.formatPath(this.vfs.getPathByInode(workingDir)),
output: output,
cmd: cmd
};

View File

@@ -143,7 +143,7 @@ function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
if (nodes.length > 1) {
const nodePath: string =
node.name === '/' ? '/:' : `${this.getFs()._getPathToNode(node).join('/').slice(1)}:`;
node.name === '/' ? '/:' : `${this.getFs().getPathByInode(node.inode).slice(1)}:`;
rows.unshift(nodePath);
rows.push('\n');
}

View File

@@ -98,6 +98,7 @@ export class VirtualFS {
}
private _findChildNodeByName(node: TreeNode, name: string): number {
console.log(name, node);
for(const childINode of node.children) {
const child = this.FsTable.get(childINode);
if(child && child.name === name) {
@@ -111,6 +112,10 @@ export class VirtualFS {
return typeof path === 'string' && path.startsWith('/');
};
getPathByInode(inode: number): string {
return this._iNodeToPathString(inode);
}
formatPath(path: string): string {
const prefix = this._iNodeToPathString(this.home);
if (path.startsWith(prefix)) {
@@ -146,7 +151,7 @@ export class VirtualFS {
return node;
}
private _getPathToNode(node: TreeNode): string[] {
/* private _getPathToNode(node: TreeNode): string[] {
const path: string[] = [];
let current = node;
path.push(node.name);
@@ -157,5 +162,5 @@ export class VirtualFS {
}
return path;
}
} */
}

View File

@@ -10,19 +10,19 @@ export function isInitializing(): boolean {
function jsonToNodeTable(data: any, parent?: number): Map<number, TreeNode> {
const FsTable: Map<number, TreeNode> = new Map<number, TreeNode>;
const keyList = Object.keys(data);
const entryList = Object.entries(data);
for(const key in keyList) {
const object = data[key];
for(let i = 0; i < entryList.length; i++) {
const object: any = entryList[i][1];
const node: TreeNode = {
inode: object.Inode,
name: object.Name,
type: object.Type,
interactible: object.Interactible,
func: object.Func,
children: [],
children: object.Children,
content: object.Content,
link: object.Link || [],
link: object.Link,
permission: {
user: {
r: object.Permission[0]?.Read,
@@ -52,7 +52,6 @@ function jsonToNodeTable(data: any, parent?: number): Map<number, TreeNode> {
FsTable.set(object.Inode, node);
}
console.log(FsTable);
return FsTable;
}

View File

@@ -99,12 +99,13 @@ export class Terminal {
getCwd(): string {
const fs: VirtualFS = this.bash.getFs();
return fs.formatPath(fs.pathArrayToString(this.bash.getCwd()));
return fs.formatPath(fs.getPathByInode(this.bash.getCwd()));
}
userLogin(username: string, passwd: string): ExitCode {
//TODO: Later reimplement the backend helper methods
/* userLogin(username: string, passwd: string): ExitCode {
return this.bash.userLogin(username, passwd);
}
} */
PrintOutput(data: PrintData) {
this.callbacks.print?.(data);