- Fixed ls (mostly)
- Fixed sorting - Many minor changes (need to fix the json serializer to include size in its results *the C++ one*)
This commit is contained in:
+58
-44
@@ -1,17 +1,22 @@
|
||||
import type { CommandDescriptor, CommandOutput } from "@core/command";
|
||||
import type { CommandIO } from "@core/command_io";
|
||||
import { type DirectoryNode, type NodePointer } from "@core/filesystem/node";
|
||||
import { NodePointer, NodeType, type DirectoryNode, type FileNode, type Node } from "@core/filesystem/node";
|
||||
import { createErrorResult, createSuccessResult } from "@core/result";
|
||||
import { getCurrentSession } from "@core/session_manager";
|
||||
import type { ShellState } from "@core/shell_state";
|
||||
import type { ShellError } from "@core/util/errors";
|
||||
import { resolvePath } from "@core/util/path_resolver";
|
||||
import { SortTreeNodeBy, sortTreeNodes } from "@core/util/sort";
|
||||
import { SortNodeBy, sortNodes } from "@core/util/sort";
|
||||
import { concatUint8Arrays } from "@termos/util/concat";
|
||||
import { convertToUnit } from "@termos/util/format_unit";
|
||||
|
||||
export const COMMAND_NAME = "ls";
|
||||
|
||||
interface DirEntry {
|
||||
name: string;
|
||||
ptr: NodePointer;
|
||||
}
|
||||
|
||||
async function main(io: CommandIO, state: ShellState, args: string[]): Promise<CommandOutput<ShellError>> {
|
||||
const entries: { ptr: NodePointer; path: string }[] = [];
|
||||
const paths: string[] = [];
|
||||
@@ -24,7 +29,7 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
noSort: false,
|
||||
noOwner: false,
|
||||
noGroup: false,
|
||||
sortBy: SortTreeNodeBy.NAME,
|
||||
sortBy: SortNodeBy.NAME,
|
||||
humanReadable: false,
|
||||
f: false,
|
||||
x: false,
|
||||
@@ -55,7 +60,7 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
continue;
|
||||
}
|
||||
if (flag === "sort" && isValidSortMethod(val)) {
|
||||
options.sortBy = val as SortTreeNodeBy;
|
||||
options.sortBy = val as SortNodeBy;
|
||||
continue;
|
||||
}
|
||||
return {
|
||||
@@ -154,16 +159,16 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
options.x = true;
|
||||
break;
|
||||
case "X":
|
||||
options.sortBy = SortTreeNodeBy.EXTENSION;
|
||||
options.sortBy = SortNodeBy.EXTENSION;
|
||||
break;
|
||||
case "u":
|
||||
options.timestamp = "atime";
|
||||
break;
|
||||
case "t":
|
||||
options.sortBy = options.timestamp as SortTreeNodeBy;
|
||||
options.sortBy = options.timestamp as SortNodeBy;
|
||||
break;
|
||||
case "S":
|
||||
options.sortBy = SortTreeNodeBy.SIZE;
|
||||
options.sortBy = SortNodeBy.SIZE;
|
||||
break;
|
||||
case "r":
|
||||
options.reverse = true;
|
||||
@@ -252,64 +257,77 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
if (options.recursive) io.writeStdout(e.encode(`${entry.path}:\n`));
|
||||
io.writeStdout(e.encode(`total ${Object.entries(node.children).length}\n`));
|
||||
|
||||
let children: TreeNode[] = Object.entries(node.children).map(c => state.filesystem.getNode(c[1])!);
|
||||
if (!options.noSort) children = sortTreeNodes(state, children, options.reverse, options.sortBy);
|
||||
let children: DirEntry[] = Array.from(node.children.entries()).map(([name, inode]) => ({
|
||||
name,
|
||||
ptr: NodePointer.of(entry.ptr.device, inode),
|
||||
}));
|
||||
if (!options.noSort) children = sortNodes(state, children, options.reverse, options.sortBy);
|
||||
|
||||
if (!options.all && !options.almostAll) children = children.filter(c => !c.name.startsWith("."));
|
||||
if (!options.all && !options.almostAll) {
|
||||
children = children.filter(c => !c.name.startsWith("."));
|
||||
}
|
||||
|
||||
if (options.long) {
|
||||
longMode(io, state, children, node);
|
||||
longMode(io, state, children);
|
||||
if (options.recursive) io.writeStdout(e.encode("\n"));
|
||||
}
|
||||
|
||||
if (options.recursive) {
|
||||
for (const child of children) {
|
||||
if (child.type === TreeNodeType.Directory) {
|
||||
for (const c of children) {
|
||||
const child = state.filesystem.getNode(c.ptr)!;
|
||||
if (child.type === NodeType.Directory) {
|
||||
let path;
|
||||
if (entry.path === "/") {
|
||||
path = "/" + child.name;
|
||||
path = "/" + c.name;
|
||||
} else if (entry.path.endsWith("/")) {
|
||||
path = entry.path + child.name;
|
||||
} else path = entry.path + "/" + child.name;
|
||||
listDirEntries({ inode: child.inode, path });
|
||||
path = entry.path + c.name;
|
||||
} else path = entry.path + "/" + c.name;
|
||||
listDirEntries({ ptr: c.ptr, path });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function longMode(io: CommandIO, state: ShellState, children: TreeNode[], current: TreeNode): void {
|
||||
function longMode(io: CommandIO, state: ShellState, children: DirEntry[]): void {
|
||||
const e = new TextEncoder();
|
||||
const buff: Uint8Array[] = [];
|
||||
const nodes: TreeNode[] = [...children];
|
||||
const nodes: DirEntry[] = [...children];
|
||||
|
||||
if (options.all) {
|
||||
/* if (options.all) {
|
||||
const parentNode = state.filesystem.getNode(current.parent)!;
|
||||
|
||||
const parent: TreeNode = { ...parentNode, name: ".." };
|
||||
const parent: NodePointer = { ...parentNode, name: ".." };
|
||||
nodes.unshift(parent);
|
||||
|
||||
const cwd: TreeNode = { ...current, name: "." };
|
||||
nodes.unshift(cwd);
|
||||
}
|
||||
} */
|
||||
|
||||
// Calculate the string size of the biggerst node in the array;
|
||||
// Sets 4 length for directories because the arbitrary size is 4096 later in the code
|
||||
const maxInodeWidth = Math.max(...nodes.map(c => c.inode.toString().length));
|
||||
const maxInodeWidth = Math.max(...nodes.map(c => c.ptr.inode.toString().length));
|
||||
|
||||
const maxSizeWidth = Math.max(
|
||||
...nodes.map(c => (c.type === TreeNodeType.File ? c.content.byteSize().toString().length : 4)),
|
||||
...nodes.map(c =>
|
||||
state.filesystem.getNode(c.ptr)!.type === NodeType.File
|
||||
? (state.filesystem.getNode(c.ptr) as FileNode).size.toString().length
|
||||
: 4,
|
||||
),
|
||||
);
|
||||
|
||||
const maxChildrenWidth = Math.max(
|
||||
...nodes.map(c =>
|
||||
c.type === TreeNodeType.Directory ? Object.entries(c.children).length.toString().length : 2,
|
||||
state.filesystem.getNode(c.ptr)!.type === NodeType.Directory
|
||||
? Object.entries((state.filesystem.getNode(c.ptr) as DirectoryNode)!.children).length
|
||||
: 2,
|
||||
),
|
||||
);
|
||||
|
||||
const namePadding = nodes.every(c => !c.name.includes(" "));
|
||||
|
||||
for (const node of nodes) {
|
||||
for (const n of nodes) {
|
||||
//Inode
|
||||
const node = state.filesystem.getNode(n.ptr)!;
|
||||
if (options.inode) {
|
||||
const inode = node.inode.toString().padStart(maxInodeWidth, " ");
|
||||
buff.push(e.encode(inode + " "));
|
||||
@@ -320,17 +338,17 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
const mode: string = parseMode(node.mode);
|
||||
|
||||
switch (node.type) {
|
||||
case TreeNodeType.Directory:
|
||||
case NodeType.Directory:
|
||||
buff.push(e.encode("d" + mode + " "));
|
||||
break;
|
||||
case TreeNodeType.File:
|
||||
case NodeType.File:
|
||||
buff.push(e.encode("-" + mode + " "));
|
||||
break;
|
||||
}
|
||||
|
||||
// Children amnt (later will be amnt of links)
|
||||
const childAmnt =
|
||||
node.type === TreeNodeType.Directory
|
||||
node.type === NodeType.Directory
|
||||
? `${Object.entries(node.children).length.toString().padStart(maxChildrenWidth, " ")} `
|
||||
: `${"10".padStart(maxChildrenWidth, " ")} `;
|
||||
|
||||
@@ -354,12 +372,12 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
// Sets the folder size to an arbitrary 4096, could change it later to smth else
|
||||
let size;
|
||||
if (options.humanReadable) {
|
||||
const bytes = node.type === TreeNodeType.File ? node.content.byteSize() : 4096;
|
||||
const bytes = node.type === NodeType.File ? node.size : 4096;
|
||||
size = convertToUnit(bytes, 1, options.si ? 1000 : 1024);
|
||||
} else {
|
||||
size =
|
||||
node.type === TreeNodeType.File
|
||||
? `${node.content.byteSize().toString().padStart(maxSizeWidth, " ")} `
|
||||
node.type === NodeType.File
|
||||
? `${node.size.toString().padStart(maxSizeWidth, " ")} `
|
||||
: `${"4096".padStart(maxSizeWidth, " ")} `;
|
||||
}
|
||||
|
||||
@@ -386,15 +404,15 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
if (options.quoteName) {
|
||||
buff.push(
|
||||
e.encode(
|
||||
`"${node.type === TreeNodeType.Directory ? node.name + '"' + (options.appendIndicator ? "/" : "") : node.name + '"'}\n`,
|
||||
`"${node.type === NodeType.Directory ? n.name + '"' + (options.appendIndicator ? "/" : "") : n.name + '"'}\n`,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
const unpadded = `${node.name.includes(" ") && !options.literal ? "'" + node.name + "'" : node.name}`;
|
||||
const unpadded = `${n.name.includes(" ") && !options.literal ? "'" + n.name + "'" : n.name}`;
|
||||
const name = `${!namePadding ? (unpadded.includes(" ") ? unpadded : " " + unpadded) : unpadded}`;
|
||||
buff.push(
|
||||
e.encode(
|
||||
`${node.type === TreeNodeType.Directory ? name + (options.appendIndicator ? "/" : "") : name}\n`,
|
||||
`${node.type === NodeType.Directory ? name + (options.appendIndicator ? "/" : "") : name}\n`,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -404,7 +422,7 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
io.writeStdout(out);
|
||||
}
|
||||
|
||||
function getDateTimestamp(node: TreeNode, ts: string): Date {
|
||||
function getDateTimestamp(node: Node, ts: string): Date {
|
||||
if (ts === "atime") return new Date(node.atime);
|
||||
if (ts === "ctime") return new Date(node.ctime);
|
||||
if (ts === "mtime") return new Date(node.mtime);
|
||||
@@ -427,16 +445,12 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
return map(owner) + map(group) + map(other);
|
||||
}
|
||||
|
||||
function isValidSortMethod(value: string): value is SortTreeNodeBy {
|
||||
return Object.values(SortTreeNodeBy).includes(value as SortTreeNodeBy);
|
||||
function isValidSortMethod(value: string): value is SortNodeBy {
|
||||
return Object.values(SortNodeBy).includes(value as SortNodeBy);
|
||||
}
|
||||
|
||||
function isValidTimestamp(
|
||||
value: string,
|
||||
): value is SortTreeNodeBy.ATIME | SortTreeNodeBy.MTIME | SortTreeNodeBy.CTIME {
|
||||
return Object.values(SortTreeNodeBy).includes(
|
||||
value as SortTreeNodeBy.ATIME | SortTreeNodeBy.MTIME | SortTreeNodeBy.CTIME,
|
||||
);
|
||||
function isValidTimestamp(value: string): value is SortNodeBy.ATIME | SortNodeBy.MTIME | SortNodeBy.CTIME {
|
||||
return Object.values(SortNodeBy).includes(value as SortNodeBy.ATIME | SortNodeBy.MTIME | SortNodeBy.CTIME);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,15 +15,7 @@ import type {
|
||||
NotADirectoryError,
|
||||
NotAFileError,
|
||||
} from "./errors";
|
||||
import {
|
||||
fromPtr,
|
||||
NodeType,
|
||||
type DirectoryNode,
|
||||
type FileNode,
|
||||
type Node,
|
||||
type NodeEntry,
|
||||
type NodePointer,
|
||||
} from "./node";
|
||||
import { NodePointer, NodeType, type DirectoryNode, type FileNode, type Node, type NodeEntry } from "./node";
|
||||
import type { IDataStore, IMetaStore, VDiskConfig } from "./vdisk";
|
||||
|
||||
export interface FileSystemConfig {
|
||||
@@ -50,11 +42,10 @@ export class FileSystem {
|
||||
}
|
||||
|
||||
private resolveNode(ptr: NodePointer): Node | undefined {
|
||||
const fptr = fromPtr(ptr);
|
||||
const dev = this._VDiskManager.getDisk(fptr.device_id);
|
||||
const dev = this._VDiskManager.getDisk(ptr.device);
|
||||
if (!dev) return undefined;
|
||||
|
||||
return dev.getNode(fptr.inode);
|
||||
return dev.getNode(ptr.inode);
|
||||
}
|
||||
|
||||
// Make async
|
||||
@@ -108,15 +99,14 @@ export class FileSystem {
|
||||
}
|
||||
|
||||
public getNodeEntries(ptr: NodePointer): readonly NodeEntry[] | undefined {
|
||||
const fptr = fromPtr(ptr);
|
||||
const dev = this._VDiskManager.getDisk(fptr.device_id);
|
||||
const dev = this._VDiskManager.getDisk(ptr.device);
|
||||
|
||||
if (!dev) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${fptr.device_id} not found`,
|
||||
message: `Device under id ${ptr.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: fptr.device_id,
|
||||
device_id: ptr.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
@@ -132,31 +122,28 @@ export class FileSystem {
|
||||
}
|
||||
|
||||
public mount(mount: NodePointer, target: NodePointer) {
|
||||
const mptr = fromPtr(mount);
|
||||
const tptr = fromPtr(target);
|
||||
|
||||
if (!this._VDiskManager.hasDisk(mptr.device_id)) {
|
||||
if (!this._VDiskManager.hasDisk(mount.device)) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${mptr.device_id} not found`,
|
||||
message: `Device under id ${mount.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: mptr.device_id,
|
||||
device_id: mount.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
if (!this._VDiskManager.hasDisk(tptr.device_id)) {
|
||||
if (!this._VDiskManager.hasDisk(target.device)) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${tptr.device_id} not found`,
|
||||
message: `Device under id ${target.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: tptr.device_id,
|
||||
device_id: target.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
if (!this.getNode(mount)) {
|
||||
throw {
|
||||
type: "NodeNotFound",
|
||||
message: `Node under inode ${mptr.inode} not found under device ${mptr.device_id}`,
|
||||
message: `Node under inode ${mount.inode} not found under device ${mount.device}`,
|
||||
timestamp: Date.now(),
|
||||
pointer: mount,
|
||||
} satisfies NodeNotFoundError;
|
||||
@@ -165,7 +152,7 @@ export class FileSystem {
|
||||
if (!this.getNode(target)) {
|
||||
throw {
|
||||
type: "NodeNotFound",
|
||||
message: `Node under inode ${tptr.inode} not found under device ${tptr.device_id}`,
|
||||
message: `Node under inode ${target.inode} not found under device ${target.device}`,
|
||||
timestamp: Date.now(),
|
||||
pointer: target,
|
||||
} satisfies NodeNotFoundError;
|
||||
@@ -192,22 +179,21 @@ export class FileSystem {
|
||||
}
|
||||
|
||||
public isFile(ptr: NodePointer): boolean {
|
||||
const fptr = fromPtr(ptr);
|
||||
const node = this.resolveNode(ptr);
|
||||
|
||||
if (!this._VDiskManager.hasDisk(fptr.device_id)) {
|
||||
if (!this._VDiskManager.hasDisk(ptr.device)) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${fptr.device_id} not found`,
|
||||
message: `Device under id ${ptr.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: fptr.device_id,
|
||||
device_id: ptr.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
if (node === undefined) {
|
||||
throw {
|
||||
type: "NodeNotFound",
|
||||
message: `Node under inode ${fptr.inode} not found under device ${fptr.device_id}`,
|
||||
message: `Node under inode ${ptr.inode} not found under device ${ptr.device}`,
|
||||
timestamp: Date.now(),
|
||||
pointer: ptr,
|
||||
} satisfies NodeNotFoundError;
|
||||
@@ -217,22 +203,21 @@ export class FileSystem {
|
||||
}
|
||||
|
||||
public isDirectory(ptr: NodePointer): boolean {
|
||||
const fptr = fromPtr(ptr);
|
||||
const node = this.resolveNode(ptr);
|
||||
|
||||
if (!this._VDiskManager.hasDisk(fptr.device_id)) {
|
||||
if (!this._VDiskManager.hasDisk(ptr.device)) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${fptr.device_id} not found`,
|
||||
message: `Device under id ${ptr.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: fptr.device_id,
|
||||
device_id: ptr.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
if (node === undefined) {
|
||||
throw {
|
||||
type: "NodeNotFound",
|
||||
message: `Node under inode ${fptr.inode} not found under device ${fptr.device_id}`,
|
||||
message: `Node under inode ${ptr.inode} not found under device ${ptr.device}`,
|
||||
timestamp: Date.now(),
|
||||
pointer: ptr,
|
||||
} satisfies NodeNotFoundError;
|
||||
@@ -242,22 +227,21 @@ export class FileSystem {
|
||||
}
|
||||
|
||||
public isSymlink(ptr: NodePointer): boolean {
|
||||
const fptr = fromPtr(ptr);
|
||||
const node = this.resolveNode(ptr);
|
||||
|
||||
if (!this._VDiskManager.hasDisk(fptr.device_id)) {
|
||||
if (!this._VDiskManager.hasDisk(ptr.device)) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${fptr.device_id} not found`,
|
||||
message: `Device under id ${ptr.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: fptr.device_id,
|
||||
device_id: ptr.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
if (node === undefined) {
|
||||
throw {
|
||||
type: "NodeNotFound",
|
||||
message: `Node under inode ${fptr.inode} not found under device ${fptr.device_id}`,
|
||||
message: `Node under inode ${ptr.inode} not found under device ${ptr.device}`,
|
||||
timestamp: Date.now(),
|
||||
pointer: ptr,
|
||||
} satisfies NodeNotFoundError;
|
||||
@@ -267,28 +251,26 @@ export class FileSystem {
|
||||
}
|
||||
|
||||
public async moveNode(source: NodePointer, destination: NodePointer, name?: string) {
|
||||
const sptr = fromPtr(source);
|
||||
const dptr = fromPtr(destination);
|
||||
const sdev = this._VDiskManager.getDisk(sptr.device_id);
|
||||
const ddev = this._VDiskManager.getDisk(dptr.device_id);
|
||||
const sdev = this._VDiskManager.getDisk(source.device);
|
||||
const ddev = this._VDiskManager.getDisk(destination.device);
|
||||
const sourceNode = this.resolveNode(source);
|
||||
const destinationNode = this.resolveNode(destination);
|
||||
|
||||
if (!sdev) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${sptr.device_id} not found`,
|
||||
message: `Device under id ${source.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: sptr.device_id,
|
||||
device_id: source.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
if (!ddev) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${dptr.device_id} not found`,
|
||||
message: `Device under id ${destination.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: dptr.device_id,
|
||||
device_id: destination.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
@@ -321,8 +303,8 @@ export class FileSystem {
|
||||
if (destinationNode.type !== NodeType.Directory) {
|
||||
throw {
|
||||
type: "NotADirectory",
|
||||
message: `Destination node under inode ${dptr.inode} is not a directory`,
|
||||
inode: dptr.inode,
|
||||
message: `Destination node under inode ${destination.inode} is not a directory`,
|
||||
inode: destination.inode,
|
||||
timestamp: Date.now(),
|
||||
nodeType: destinationNode.type,
|
||||
} satisfies NotADirectoryError;
|
||||
@@ -372,8 +354,8 @@ export class FileSystem {
|
||||
} satisfies DirectoryLoopError;
|
||||
}
|
||||
|
||||
if (sptr.device_id === dptr.device_id) {
|
||||
await ddev.moveNodeEntry(pinode, dptr.inode, s_entry[0].name, name);
|
||||
if (source.device === destination.device) {
|
||||
await ddev.moveNodeEntry(pinode, destination.inode, s_entry[0].name, name);
|
||||
} else {
|
||||
console.error("cross device node movement not yet implemented");
|
||||
}
|
||||
@@ -394,16 +376,15 @@ export class FileSystem {
|
||||
| { type: NodeType.Directory; mode: number; owner: number; group: number }
|
||||
| { type: NodeType.Symlink; mode: number; owner: number; group: number; target: string },
|
||||
) {
|
||||
const pptr = fromPtr(parent);
|
||||
const pdev = this._VDiskManager.getDisk(pptr.device_id);
|
||||
const pdev = this._VDiskManager.getDisk(parent.device);
|
||||
const parentNode = this.resolveNode(parent);
|
||||
|
||||
if (!pdev) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${pptr.device_id} not found`,
|
||||
message: `Device under id ${parent.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: pptr.device_id,
|
||||
device_id: parent.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
@@ -419,8 +400,8 @@ export class FileSystem {
|
||||
if (parentNode.type !== NodeType.Directory) {
|
||||
throw {
|
||||
type: "NotADirectory",
|
||||
message: `Destination node under inode ${pptr.inode} is not a directory`,
|
||||
inode: pptr.inode,
|
||||
message: `Destination node under inode ${parent.inode} is not a directory`,
|
||||
inode: parent.inode,
|
||||
timestamp: Date.now(),
|
||||
nodeType: parentNode.type,
|
||||
} satisfies NotADirectoryError;
|
||||
@@ -446,14 +427,13 @@ export class FileSystem {
|
||||
} satisfies InvalidNodeNameError;
|
||||
}
|
||||
|
||||
await pdev.createNodeEntry(pptr.inode, name, data);
|
||||
await pdev.createNodeEntry(parent.inode, name, data);
|
||||
}
|
||||
|
||||
public async deleteNode(target: NodePointer) {
|
||||
const tptr = fromPtr(target);
|
||||
const tdev = this._VDiskManager.getDisk(tptr.device_id);
|
||||
const tdev = this._VDiskManager.getDisk(target.device);
|
||||
|
||||
if (tptr.inode === 0) {
|
||||
if (target.inode === 0) {
|
||||
throw {
|
||||
type: "IllegalMutation",
|
||||
message: `Attempt at illegal mutation of node under inode 0 (root)`,
|
||||
@@ -464,9 +444,9 @@ export class FileSystem {
|
||||
if (!tdev) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${tptr.device_id} not found`,
|
||||
message: `Device under id ${target.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: tptr.device_id,
|
||||
device_id: target.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
@@ -484,16 +464,15 @@ export class FileSystem {
|
||||
}
|
||||
|
||||
public async writeContent(target: NodePointer, content: Blob) {
|
||||
const ptr = fromPtr(target);
|
||||
const dev = this._VDiskManager.getDisk(ptr.device_id);
|
||||
const dev = this._VDiskManager.getDisk(target.device);
|
||||
const node = this.resolveNode(target);
|
||||
|
||||
if (!dev) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${ptr.device_id} not found`,
|
||||
message: `Device under id ${target.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: ptr.device_id,
|
||||
device_id: target.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
@@ -510,7 +489,7 @@ export class FileSystem {
|
||||
throw {
|
||||
type: "NotAFile",
|
||||
message: `Node is not a file`,
|
||||
inode: ptr.inode,
|
||||
inode: target.inode,
|
||||
timestamp: Date.now(),
|
||||
nodeType: node.type,
|
||||
} satisfies NotAFileError;
|
||||
@@ -520,16 +499,15 @@ export class FileSystem {
|
||||
}
|
||||
|
||||
public streamContent(target: NodePointer): Readable {
|
||||
const ptr = fromPtr(target);
|
||||
const dev = this._VDiskManager.getDisk(ptr.device_id);
|
||||
const dev = this._VDiskManager.getDisk(target.device);
|
||||
const node = this.resolveNode(target);
|
||||
|
||||
if (!dev) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${ptr.device_id} not found`,
|
||||
message: `Device under id ${target.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: ptr.device_id,
|
||||
device_id: target.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
@@ -546,7 +524,7 @@ export class FileSystem {
|
||||
throw {
|
||||
type: "NotAFile",
|
||||
message: `Node is not a file`,
|
||||
inode: ptr.inode,
|
||||
inode: target.inode,
|
||||
timestamp: Date.now(),
|
||||
nodeType: node.type,
|
||||
} satisfies NotAFileError;
|
||||
@@ -556,16 +534,15 @@ export class FileSystem {
|
||||
}
|
||||
|
||||
public async modifyNode(target: NodePointer, data: { mode?: number; owner?: number; group?: number }) {
|
||||
const ptr = fromPtr(target);
|
||||
const dev = this._VDiskManager.getDisk(ptr.device_id);
|
||||
const dev = this._VDiskManager.getDisk(target.device);
|
||||
const node = this.resolveNode(target);
|
||||
|
||||
if (!dev) {
|
||||
throw {
|
||||
type: "DeviceNotFound",
|
||||
message: `Device under id ${ptr.device_id} not found`,
|
||||
message: `Device under id ${target.device} not found`,
|
||||
timestamp: Date.now(),
|
||||
device_id: ptr.device_id,
|
||||
device_id: target.device,
|
||||
} satisfies DeviceNotFoundError;
|
||||
}
|
||||
|
||||
@@ -582,7 +559,7 @@ export class FileSystem {
|
||||
throw {
|
||||
type: "NotAFile",
|
||||
message: `Node is not a file`,
|
||||
inode: ptr.inode,
|
||||
inode: target.device,
|
||||
timestamp: Date.now(),
|
||||
nodeType: node.type,
|
||||
} satisfies NotAFileError;
|
||||
@@ -591,14 +568,14 @@ export class FileSystem {
|
||||
await dev.writeNodeEntry(node.inode, data);
|
||||
}
|
||||
|
||||
public canRead(nodep: NodePointer, user: UserInfo): boolean {
|
||||
const node = this.resolveNode(nodep);
|
||||
public canRead(ptr: NodePointer, user: UserInfo): boolean {
|
||||
const node = this.resolveNode(ptr);
|
||||
if (!node) {
|
||||
throw {
|
||||
type: "NodeNotFound",
|
||||
message: `Node under ${nodep} not found`,
|
||||
message: `Node under ${ptr} not found`,
|
||||
timestamp: Date.now(),
|
||||
pointer: nodep,
|
||||
pointer: ptr,
|
||||
} satisfies NodeNotFoundError;
|
||||
}
|
||||
|
||||
@@ -613,14 +590,14 @@ export class FileSystem {
|
||||
}
|
||||
}
|
||||
|
||||
public canWrite(nodep: NodePointer, user: UserInfo): boolean {
|
||||
const node = this.resolveNode(nodep);
|
||||
public canWrite(ptr: NodePointer, user: UserInfo): boolean {
|
||||
const node = this.resolveNode(ptr);
|
||||
if (!node) {
|
||||
throw {
|
||||
type: "NodeNotFound",
|
||||
message: `Node under ${nodep} not found`,
|
||||
message: `Node under ${ptr} not found`,
|
||||
timestamp: Date.now(),
|
||||
pointer: nodep,
|
||||
pointer: ptr,
|
||||
} satisfies NodeNotFoundError;
|
||||
}
|
||||
|
||||
@@ -635,14 +612,14 @@ export class FileSystem {
|
||||
}
|
||||
}
|
||||
|
||||
public canExecute(nodep: NodePointer, user: UserInfo): boolean {
|
||||
const node = this.resolveNode(nodep);
|
||||
public canExecute(ptr: NodePointer, user: UserInfo): boolean {
|
||||
const node = this.resolveNode(ptr);
|
||||
if (!node) {
|
||||
throw {
|
||||
type: "NodeNotFound",
|
||||
message: `Node under ${nodep} not found`,
|
||||
message: `Node under ${ptr} not found`,
|
||||
timestamp: Date.now(),
|
||||
pointer: nodep,
|
||||
pointer: ptr,
|
||||
} satisfies NodeNotFoundError;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
import type { Blob } from "node:buffer";
|
||||
import { Readable } from "node:stream";
|
||||
import { blob } from "node:stream/consumers";
|
||||
import {
|
||||
NodeType,
|
||||
toPtr,
|
||||
type DirectoryNode,
|
||||
type Node,
|
||||
type NodeEntry,
|
||||
type NodeHash,
|
||||
type NodePointer,
|
||||
} from "./node";
|
||||
import { NodePointer, NodeType, type DirectoryNode, type Node, type NodeEntry, type NodeHash } from "./node";
|
||||
|
||||
export function DefaultVDiskConfig(id: number): VDiskConfig {
|
||||
const base = new Map();
|
||||
@@ -149,6 +141,7 @@ export class VDisk {
|
||||
|
||||
const root = this.getNode(0) as DirectoryNode;
|
||||
for (const [name, inode] of root.children) {
|
||||
if (name === "." || name === "..") continue;
|
||||
stack.push([inode, 0, this._id, name]);
|
||||
}
|
||||
|
||||
@@ -157,7 +150,7 @@ export class VDisk {
|
||||
const node = this.getNode(inode);
|
||||
if (node === undefined) continue;
|
||||
|
||||
const key = toPtr({ device_id: this._id, inode });
|
||||
const key = NodePointer.of(this._id, inode);
|
||||
const entry = {
|
||||
pinode,
|
||||
pdevice_id,
|
||||
@@ -170,6 +163,7 @@ export class VDisk {
|
||||
|
||||
if (node.type === NodeType.Directory) {
|
||||
for (const [name, cinode] of node.children) {
|
||||
if (name === "." || name === "..") continue;
|
||||
stack.push([cinode, inode, pdevice_id, name]);
|
||||
}
|
||||
}
|
||||
|
||||
+30
-62
@@ -1,4 +1,3 @@
|
||||
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";
|
||||
@@ -14,43 +13,26 @@ export enum SortNodeBy {
|
||||
CTIME = "ctime",
|
||||
}
|
||||
|
||||
export function sortNodes(
|
||||
export function sortNodes<T extends { name: string; ptr: NodePointer }>(
|
||||
state: ShellState,
|
||||
arr: NodePointer[],
|
||||
arr: T[],
|
||||
r: boolean = false,
|
||||
by: SortNodeBy = SortNodeBy.NAME,
|
||||
): NodePointer[] {
|
||||
): T[] {
|
||||
if (arr.length === 0) return [];
|
||||
|
||||
/* const nodes: NodePointer[] = [];
|
||||
|
||||
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 {
|
||||
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);
|
||||
|
||||
return arr;
|
||||
|
||||
/* 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: NodePointer[], r: boolean, by: SortNodeBy, start: number, end: number, state: ShellState): void {
|
||||
function nodeQS(
|
||||
arr: { name: string; ptr: NodePointer }[],
|
||||
r: boolean,
|
||||
by: SortNodeBy,
|
||||
start: number,
|
||||
end: number,
|
||||
state: ShellState,
|
||||
): void {
|
||||
if (end <= start) return;
|
||||
|
||||
const pivot = partitionNodeArray(arr, r, by, start, end, state);
|
||||
@@ -59,7 +41,7 @@ function nodeQS(arr: NodePointer[], r: boolean, by: SortNodeBy, start: number, e
|
||||
}
|
||||
|
||||
function partitionNodeArray(
|
||||
part: NodePointer[],
|
||||
part: { name: string; ptr: NodePointer }[],
|
||||
r: boolean,
|
||||
by: SortNodeBy,
|
||||
start: number,
|
||||
@@ -86,21 +68,17 @@ function partitionNodeArray(
|
||||
return i;
|
||||
}
|
||||
|
||||
function compareNode(a: NodePointer, b: NodePointer, by: SortNodeBy, r: boolean, state: ShellState): number {
|
||||
function compareNode(
|
||||
a: { name: string; ptr: NodePointer },
|
||||
b: { name: string; ptr: NodePointer },
|
||||
by: SortNodeBy,
|
||||
r: boolean,
|
||||
state: ShellState,
|
||||
): number {
|
||||
switch (by) {
|
||||
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 A: string = a.name;
|
||||
const B: string = b.name;
|
||||
const min = Math.min(A.length, B.length);
|
||||
|
||||
for (let i = 0; i < min; i++) {
|
||||
@@ -118,8 +96,8 @@ function compareNode(a: NodePointer, b: NodePointer, by: SortNodeBy, r: boolean,
|
||||
case SortNodeBy.MTIME:
|
||||
case SortNodeBy.ATIME:
|
||||
case SortNodeBy.CTIME: {
|
||||
const nodeA = state.filesystem.getNode(a)!;
|
||||
const nodeB = state.filesystem.getNode(a)!;
|
||||
const nodeA = state.filesystem.getNode(a.ptr)!;
|
||||
const nodeB = state.filesystem.getNode(b.ptr)!;
|
||||
const A: number = nodeA[by];
|
||||
const B: number = nodeB[by];
|
||||
|
||||
@@ -127,8 +105,8 @@ function compareNode(a: NodePointer, b: NodePointer, by: SortNodeBy, r: boolean,
|
||||
}
|
||||
|
||||
case SortNodeBy.SIZE: {
|
||||
const nodeA = state.filesystem.getNode(a)!;
|
||||
const nodeB = state.filesystem.getNode(a)!;
|
||||
const nodeA = state.filesystem.getNode(a.ptr)!;
|
||||
const nodeB = state.filesystem.getNode(b.ptr)!;
|
||||
const A: number = (nodeA as FileNode).size;
|
||||
const B: number = (nodeB as FileNode).size;
|
||||
|
||||
@@ -136,18 +114,8 @@ function compareNode(a: NodePointer, b: NodePointer, by: SortNodeBy, r: boolean,
|
||||
}
|
||||
|
||||
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 A: string = a.name.split(".").pop() ?? "";
|
||||
const B: string = b.name.split(".").pop() ?? "";
|
||||
const min = Math.min(A.length, B.length);
|
||||
|
||||
for (let i = 0; i < min; i++) {
|
||||
@@ -163,12 +131,12 @@ function compareNode(a: NodePointer, b: NodePointer, by: SortNodeBy, r: boolean,
|
||||
}
|
||||
|
||||
case SortNodeBy.INODE: {
|
||||
return r ? a.inode - b.inode : b.inode - a.inode;
|
||||
return r ? a.ptr.inode - b.ptr.inode : b.ptr.inode - a.ptr.inode;
|
||||
}
|
||||
|
||||
case SortNodeBy.TYPE: {
|
||||
const nodeA = state.filesystem.getNode(a)!;
|
||||
const nodeB = state.filesystem.getNode(a)!;
|
||||
const nodeA = state.filesystem.getNode(a.ptr)!;
|
||||
const nodeB = state.filesystem.getNode(a.ptr)!;
|
||||
return r ? nodeB.type - nodeA.type : nodeA.type - nodeB.type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { FileSystem } from "@core/filesystem/filesystem";
|
||||
import { fromPtr, NodeType, toPtr, type NodeEntry, type NodePointer } from "@core/filesystem/node";
|
||||
import { NodePointer, NodeType, type NodeEntry } from "@core/filesystem/node";
|
||||
|
||||
export function dnTraverseTree(fs: FileSystem, root: NodePointer): NodePointer[] {
|
||||
if (fs.getNode(root) === undefined) return [];
|
||||
@@ -18,7 +18,7 @@ export function dnTraverseTree(fs: FileSystem, root: NodePointer): NodePointer[]
|
||||
const children = Array.from(node.children.values());
|
||||
for (let i = children.length - 1; i >= 0; i--) {
|
||||
const child = children[i]!;
|
||||
const pointer = toPtr({ device_id: Number(ptr.split(":")[0]), inode: child });
|
||||
const pointer = NodePointer.of(ptr.device, child);
|
||||
stack.push(pointer);
|
||||
}
|
||||
}
|
||||
@@ -32,12 +32,12 @@ export function upTraverseTree(fs: FileSystem, ptr: NodePointer): NodePointer[]
|
||||
const result: NodePointer[] = [ptr];
|
||||
let currentPtr = ptr;
|
||||
|
||||
while (fromPtr(currentPtr).inode !== 0) {
|
||||
while (currentPtr.inode !== 0) {
|
||||
const entries = fs.getNodeEntries(currentPtr);
|
||||
if (!entries || entries.length === 0) throw new Error(`No reverse-index entry found for ${currentPtr}`);
|
||||
|
||||
const parent = entries[0] as NodeEntry;
|
||||
currentPtr = toPtr({ device_id: parent.pdevice_id, inode: parent.pinode });
|
||||
currentPtr = NodePointer.of(parent.pdevice_id, parent.pinode);
|
||||
result.push(currentPtr);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export function deserializeFileSystem(json: string): { id: number; map: Map<numb
|
||||
const raw = JSON.parse(json);
|
||||
|
||||
// prettier-ignore
|
||||
function parseNode(tree: any, map: Map<number, Node>): void { // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
function parseNode(tree: any, parent: number, map: Map<number, Node>): void { // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
if(tree === null || tree.type === undefined) {
|
||||
const time = Date.now();
|
||||
const defaultNode: DirectoryNode = {
|
||||
@@ -32,7 +32,7 @@ export function deserializeFileSystem(json: string): { id: number; map: Map<numb
|
||||
const children: Map<string, number> = new Map();
|
||||
|
||||
for (const child of tree.children) {
|
||||
parseNode(child, map);
|
||||
parseNode(child, tree.inode, map);
|
||||
children.set(child.name, child.inode);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ export function deserializeFileSystem(json: string): { id: number; map: Map<numb
|
||||
atime: tree.atime,
|
||||
children,
|
||||
};
|
||||
children.set('..', parent);
|
||||
children.set('.', tree.inode);
|
||||
map.set(tree.inode, Object.freeze(directoryNode));
|
||||
break;
|
||||
}
|
||||
@@ -92,7 +94,7 @@ export function deserializeFileSystem(json: string): { id: number; map: Map<numb
|
||||
const result: { id: number; map: Map<number, Node> }[] = [];
|
||||
for (const dev of raw.dev) {
|
||||
const map = new Map();
|
||||
parseNode(dev.tree, map);
|
||||
parseNode(dev.tree, dev.tree.inode, map);
|
||||
|
||||
result.push({ id: dev.id, map });
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { FileSystem } from "@core/filesystem/filesystem";
|
||||
import { fromPtr, NodeType, toPtr, type NodePointer, type SymlinkNode } from "@core/filesystem/node";
|
||||
import { NodePointer, NodeType, type SymlinkNode } from "@core/filesystem/node";
|
||||
|
||||
type Frame = {
|
||||
ptr: NodePointer;
|
||||
@@ -12,13 +12,12 @@ function getSortedChildren(fs: FileSystem, ptr: NodePointer): Array<{ name: stri
|
||||
const node = fs.getNode(ptr);
|
||||
if (!node || node.type !== NodeType.Directory) return [];
|
||||
|
||||
const { device_id } = fromPtr(ptr);
|
||||
const entries = Array.from(node.children.entries());
|
||||
entries.sort(([a], [b]) => a.localeCompare(b));
|
||||
|
||||
return entries.map(([name, inode]) => ({
|
||||
name,
|
||||
ptr: toPtr({ device_id, inode }),
|
||||
ptr: NodePointer.of(ptr.device, inode),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -26,8 +25,7 @@ function mountSuffix(fs: FileSystem, ptr: NodePointer): string {
|
||||
if (!fs.isMountPoint(ptr)) return "";
|
||||
const target = fs.getMountPoint(ptr);
|
||||
if (!target) return " -> [mount: target missing]";
|
||||
const t = fromPtr(target);
|
||||
return ` -> (${t.device_id}:${t.inode})`;
|
||||
return ` -> ${target.toString()}`;
|
||||
}
|
||||
|
||||
function symlinkSuffix(node: { type: NodeType; target?: string }): string {
|
||||
@@ -39,14 +37,14 @@ export function printTree(fs: FileSystem, root: NodePointer, rootLabel = "/"): s
|
||||
if (rootNode === undefined) return "";
|
||||
|
||||
const lines: string[] = [];
|
||||
const rootFptr = fromPtr(root);
|
||||
const rootSuffix = mountSuffix(fs, root) + symlinkSuffix(rootNode);
|
||||
lines.push(`${rootLabel} (${rootFptr.device_id}:${rootFptr.inode})${rootSuffix}`);
|
||||
lines.push(`${rootLabel} ${root.toString()}${rootSuffix}`);
|
||||
|
||||
const stack: Frame[] = [];
|
||||
const rootChildren = getSortedChildren(fs, root);
|
||||
for (let i = rootChildren.length - 1; i >= 0; i--) {
|
||||
const child = rootChildren[i]!;
|
||||
if (child.name.startsWith(".")) continue;
|
||||
const isLast = i === rootChildren.length - 1;
|
||||
stack.push({ ptr: child.ptr, name: child.name, prefix: "", isLast });
|
||||
}
|
||||
@@ -56,10 +54,9 @@ export function printTree(fs: FileSystem, root: NodePointer, rootLabel = "/"): s
|
||||
const node = fs.getNode(frame.ptr);
|
||||
if (!node) continue;
|
||||
|
||||
const fptr = fromPtr(frame.ptr);
|
||||
const connector = frame.isLast ? "└── " : "├── ";
|
||||
const suffix = mountSuffix(fs, frame.ptr) + symlinkSuffix(node);
|
||||
lines.push(`${frame.prefix}${connector}${frame.name} (${fptr.device_id}:${fptr.inode})${suffix}`);
|
||||
lines.push(`${frame.prefix}${connector}${frame.name} ${frame.ptr.toString()}${suffix}`);
|
||||
|
||||
if (node.type === NodeType.Directory && !fs.isMountPoint(frame.ptr)) {
|
||||
const childPrefix = frame.prefix + (frame.isLast ? " " : "│ ");
|
||||
@@ -67,6 +64,7 @@ export function printTree(fs: FileSystem, root: NodePointer, rootLabel = "/"): s
|
||||
|
||||
for (let i = children.length - 1; i >= 0; i--) {
|
||||
const child = children[i]!;
|
||||
if (child.name.startsWith(".")) continue;
|
||||
const childIsLast = i === children.length - 1;
|
||||
stack.push({
|
||||
ptr: child.ptr,
|
||||
@@ -82,7 +80,7 @@ export function printTree(fs: FileSystem, root: NodePointer, rootLabel = "/"): s
|
||||
}
|
||||
|
||||
export function printDeviceTree(fs: FileSystem, deviceId: number, rootLabel?: string): string {
|
||||
return printTree(fs, toPtr({ device_id: deviceId, inode: 0 }), rootLabel ?? `disk-${deviceId}:/`);
|
||||
return printTree(fs, NodePointer.of(deviceId, 0), rootLabel ?? `disk-${deviceId}:/`);
|
||||
}
|
||||
|
||||
export function printAllDeviceTrees(fs: FileSystem, deviceIds?: number[]): string {
|
||||
|
||||
Reference in New Issue
Block a user