- Added a safety check in serializer.ts to look for fields containing undefined

- Updated the fs json to contain the new result from the fixed serializer that parses the link counts
- Updated ls to use proper link counts and sizes in the long format (apart from dir sizes which remain at arbitrary 4096)
This commit is contained in:
2026-11-14 10:49:51 +01:00
parent de1ce64226
commit d4ec6b0c49
4 changed files with 26 additions and 29 deletions
+11 -27
View File
@@ -274,6 +274,7 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
if (options.recursive) {
for (const c of children) {
if (c.name.match(/^[.]{1,2}$/)) continue;
const child = state.filesystem.getNode(c.ptr)!;
if (child.type === NodeType.Directory) {
let path;
@@ -293,16 +294,6 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
const buff: Uint8Array[] = [];
const nodes: DirEntry[] = [...children];
/* if (options.all) {
const parentNode = state.filesystem.getNode(current.parent)!;
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.ptr.inode.toString().length));
@@ -315,23 +306,21 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
),
);
const maxChildrenWidth = Math.max(
...nodes.map(c =>
state.filesystem.getNode(c.ptr)!.type === NodeType.Directory
? Object.entries((state.filesystem.getNode(c.ptr) as DirectoryNode)!.children).length
: 2,
),
const maxLinksWidth = Math.max(
...nodes.map((c): number => {
const node = state.filesystem.getNode(c.ptr)!;
const o = node.link_count.toString().length;
return o;
}),
);
const namePadding = nodes.every(c => !c.name.includes(" "));
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 + " "));
//io.writeStdout(e.encode(inode + " "));
}
// Mode
@@ -346,13 +335,9 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
break;
}
// Children amnt (later will be amnt of links)
const childAmnt =
node.type === NodeType.Directory
? `${Object.entries(node.children).length.toString().padStart(maxChildrenWidth, " ")} `
: `${"10".padStart(maxChildrenWidth, " ")} `;
buff.push(e.encode(childAmnt));
//Link count
const linkCount = node.link_count.toString().padStart(maxLinksWidth, " ");
buff.push(e.encode(linkCount));
// owner group
if (options.noGroup) {
@@ -384,7 +369,6 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
buff.push(e.encode(size));
//Timestamp
// for now only mtime, need a helper function for all the formatting later on
const date = getDateTimestamp(node, options.timestamp);
if (options.fullTime) {
buff.push(
+1 -1
View File
File diff suppressed because one or more lines are too long
+13
View File
@@ -52,6 +52,11 @@ export function deserializeFileSystem(json: string): { dstore: IDataStore; mstor
atime: tree.atime,
children,
};
if(Object.values(directoryNode).some(e => e === undefined))
throw new Error(`Serialization failed, object contains undefined fields - ${directoryNode}`);
children.set('..', parent);
children.set('.', tree.inode);
map.set(tree.inode, Object.freeze(directoryNode));
@@ -72,6 +77,10 @@ export function deserializeFileSystem(json: string): { dstore: IDataStore; mstor
content: uuid,
size: tree.size,
};
if(Object.values(fileNode).some(e => e === undefined))
throw new Error(`Serialization failed, object contains undefined fields - ${fileNode}`);
const buff: Uint8Array<ArrayBuffer> = Uint8Array.from(tree.content);
store.put(uuid, new Blob([buff]));
map.set(tree.inode, Object.freeze(fileNode));
@@ -90,6 +99,10 @@ export function deserializeFileSystem(json: string): { dstore: IDataStore; mstor
atime: tree.atime,
target: tree.target,
};
if(Object.values(symlinkNode).some(e => e === undefined))
throw new Error(`Serialization failed, object contains undefined fields - ${symlinkNode}`);
map.set(tree.inode, Object.freeze(symlinkNode));
break;
}