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;
}
} */
}