Skip to content

Commit 96fc5dd

Browse files
committed
Infra: handle win32 unknown inode in file identity checks
1 parent 7853c4f commit 96fc5dd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/infra/file-identity.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@ describe("sameFileIdentity", () => {
2727
expect(sameFileIdentity(stat(7, 11), stat(8, 11), "win32")).toBe(false);
2828
});
2929

30+
it("accepts win32 inode mismatch when either side is 0", () => {
31+
expect(sameFileIdentity(stat(7, 0), stat(7, 11), "win32")).toBe(true);
32+
expect(sameFileIdentity(stat(7, 12), stat(7, 0), "win32")).toBe(true);
33+
});
34+
35+
it("keeps inode strictness on non-windows", () => {
36+
expect(sameFileIdentity(stat(7, 0), stat(7, 11), "linux")).toBe(false);
37+
});
38+
3039
it("handles bigint stats", () => {
3140
expect(sameFileIdentity(stat(0n, 11n), stat(8n, 11n), "win32")).toBe(true);
41+
expect(sameFileIdentity(stat(7n, 0n), stat(7n, 11n), "win32")).toBe(true);
3242
});
3343
});

src/infra/file-identity.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ function isZero(value: number | bigint): boolean {
77
return value === 0 || value === 0n;
88
}
99

10+
function isUnknownIdentity(value: number | bigint): boolean {
11+
return isZero(value);
12+
}
13+
1014
export function sameFileIdentity(
1115
left: FileIdentityStat,
1216
right: FileIdentityStat,
1317
platform: NodeJS.Platform = process.platform,
1418
): boolean {
15-
if (left.ino !== right.ino) {
19+
const inodeMatches =
20+
left.ino === right.ino ||
21+
(platform === "win32" && (isUnknownIdentity(left.ino) || isUnknownIdentity(right.ino)));
22+
if (!inodeMatches) {
1623
return false;
1724
}
1825

@@ -21,5 +28,5 @@ export function sameFileIdentity(
2128
if (left.dev === right.dev) {
2229
return true;
2330
}
24-
return platform === "win32" && (isZero(left.dev) || isZero(right.dev));
31+
return platform === "win32" && (isUnknownIdentity(left.dev) || isUnknownIdentity(right.dev));
2532
}

0 commit comments

Comments
 (0)