mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 05:37:27 +00:00
Infra: handle win32 unknown inode in file identity checks
This commit is contained in:
@@ -27,7 +27,17 @@ describe("sameFileIdentity", () => {
|
|||||||
expect(sameFileIdentity(stat(7, 11), stat(8, 11), "win32")).toBe(false);
|
expect(sameFileIdentity(stat(7, 11), stat(8, 11), "win32")).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("accepts win32 inode mismatch when either side is 0", () => {
|
||||||
|
expect(sameFileIdentity(stat(7, 0), stat(7, 11), "win32")).toBe(true);
|
||||||
|
expect(sameFileIdentity(stat(7, 12), stat(7, 0), "win32")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps inode strictness on non-windows", () => {
|
||||||
|
expect(sameFileIdentity(stat(7, 0), stat(7, 11), "linux")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it("handles bigint stats", () => {
|
it("handles bigint stats", () => {
|
||||||
expect(sameFileIdentity(stat(0n, 11n), stat(8n, 11n), "win32")).toBe(true);
|
expect(sameFileIdentity(stat(0n, 11n), stat(8n, 11n), "win32")).toBe(true);
|
||||||
|
expect(sameFileIdentity(stat(7n, 0n), stat(7n, 11n), "win32")).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,12 +7,19 @@ function isZero(value: number | bigint): boolean {
|
|||||||
return value === 0 || value === 0n;
|
return value === 0 || value === 0n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isUnknownIdentity(value: number | bigint): boolean {
|
||||||
|
return isZero(value);
|
||||||
|
}
|
||||||
|
|
||||||
export function sameFileIdentity(
|
export function sameFileIdentity(
|
||||||
left: FileIdentityStat,
|
left: FileIdentityStat,
|
||||||
right: FileIdentityStat,
|
right: FileIdentityStat,
|
||||||
platform: NodeJS.Platform = process.platform,
|
platform: NodeJS.Platform = process.platform,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (left.ino !== right.ino) {
|
const inodeMatches =
|
||||||
|
left.ino === right.ino ||
|
||||||
|
(platform === "win32" && (isUnknownIdentity(left.ino) || isUnknownIdentity(right.ino)));
|
||||||
|
if (!inodeMatches) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,5 +28,5 @@ export function sameFileIdentity(
|
|||||||
if (left.dev === right.dev) {
|
if (left.dev === right.dev) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return platform === "win32" && (isZero(left.dev) || isZero(right.dev));
|
return platform === "win32" && (isUnknownIdentity(left.dev) || isUnknownIdentity(right.dev));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user