Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions scripts/verify/rsi-assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import os from 'node:os';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { runProcess } from '../../dist/utils/run-process.js';
import { diskUsage } from '../../dist/core/rsi/asset-io.js';
import {
RsiAssetStore,
RsiStore,
Expand Down Expand Up @@ -37,6 +38,41 @@ const put = (content, extra = {}) =>
...extra,
});
try {
// NTFS file IDs may exceed Number precision; adjacent IDs must not become a cycle.
const inodeRoot = path.join(root, 'exact-inodes');
fs.mkdirSync(inodeRoot);
const firstFile = path.join(inodeRoot, 'first');
const secondFile = path.join(inodeRoot, 'second');
const hardLink = path.join(inodeRoot, 'first-link');
fs.writeFileSync(firstFile, 'first');
fs.writeFileSync(secondFile, 'second');
fs.linkSync(firstFile, hardLink);
const firstInode = 2n ** 53n;
assert.equal(Number(firstInode), Number(firstInode + 1n));
const inodes = new Map([
[inodeRoot, firstInode],
[firstFile, firstInode + 1n],
[secondFile, firstInode + 2n],
[hardLink, firstInode + 1n],
]);
const originalLstat = fs.lstatSync;
try {
fs.lstatSync = (file, options) => {
const stat = originalLstat(file, options);
const inode = inodes.get(String(file));
if (inode !== undefined) stat.ino = options?.bigint ? inode : Number(inode);
return stat;
};
assert.equal(
diskUsage(inodeRoot),
11,
'distinct IDs count while hard links remain deduplicated'
);
} finally {
fs.lstatSync = originalLstat;
}
fs.rmSync(inodeRoot, { recursive: true });

const legacy = store.read(scope);
const adapter = {
id: 'legacy-adapter',
Expand Down
8 changes: 4 additions & 4 deletions src/core/rsi/asset-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export function diskUsage(directory: string, workspaces: readonly string[] = [])
};
function walk(file: string, workspace?: string): number {
if (++count > 100_000) throw new RsiError('asset_scan_limit', 409);
let stat: fs.Stats;
let stat: fs.BigIntStats;
try {
stat = fs.lstatSync(file);
stat = fs.lstatSync(file, { bigint: true });
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return 0;
throw error;
Expand All @@ -87,14 +87,14 @@ export function diskUsage(directory: string, workspaces: readonly string[] = [])
seen.add(key);
active.add(key);
try {
return stat.size + walk(target, workspace);
return Number(stat.size) + walk(target, workspace);
} finally {
active.delete(key);
}
}
if (seen.has(key)) return 0;
seen.add(key);
if (stat.isFile()) return stat.size;
if (stat.isFile()) return Number(stat.size);
if (!stat.isDirectory()) throw new RsiError('asset_special_file_refused', 409);
active.add(key);
try {
Expand Down
Loading