- 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:
@@ -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