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:
@@ -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
|
||||
};
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user