( lockDirPath: string, ownerFilePath: string, ownerGraceMs: number, )
| 66 | } |
| 67 | |
| 68 | function clearStaleProcessLock( |
| 69 | lockDirPath: string, |
| 70 | ownerFilePath: string, |
| 71 | ownerGraceMs: number, |
| 72 | ): boolean { |
| 73 | let ownerStats: fs.Stats | null = null; |
| 74 | try { |
| 75 | ownerStats = fs.statSync(lockDirPath); |
| 76 | } catch { |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | const owner = readProcessLockOwner(ownerFilePath); |
| 81 | if (owner) { |
| 82 | if (isLiveProcessLockOwner(owner)) { |
| 83 | return false; |
| 84 | } |
| 85 | fs.rmSync(lockDirPath, { recursive: true, force: true }); |
| 86 | return true; |
| 87 | } |
| 88 | if (Date.now() - ownerStats.mtimeMs < ownerGraceMs) { |
| 89 | return false; |
| 90 | } |
| 91 | fs.rmSync(lockDirPath, { recursive: true, force: true }); |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | function readProcessLockOwner(ownerFilePath: string): ProcessLockOwner | null { |
| 96 | try { |
no test coverage detected