mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 23:04:32 +00:00
fix: align windows safe-open file identity checks
This commit is contained in:
25
src/infra/file-identity.ts
Normal file
25
src/infra/file-identity.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export type FileIdentityStat = {
|
||||
dev: number | bigint;
|
||||
ino: number | bigint;
|
||||
};
|
||||
|
||||
function isZero(value: number | bigint): boolean {
|
||||
return value === 0 || value === 0n;
|
||||
}
|
||||
|
||||
export function sameFileIdentity(
|
||||
left: FileIdentityStat,
|
||||
right: FileIdentityStat,
|
||||
platform: NodeJS.Platform = process.platform,
|
||||
): boolean {
|
||||
if (left.ino !== right.ino) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// On Windows, path-based stat calls can report dev=0 while fd-based stat
|
||||
// reports a real volume serial; treat either-side dev=0 as "unknown device".
|
||||
if (left.dev === right.dev) {
|
||||
return true;
|
||||
}
|
||||
return platform === "win32" && (isZero(left.dev) || isZero(right.dev));
|
||||
}
|
||||
Reference in New Issue
Block a user