()
| 661 | * Mirrors acquireLock but with the dream TTL and its own path. |
| 662 | */ |
| 663 | export function acquireDreamMarker(): boolean { |
| 664 | const path = dreamMarkerPath(); |
| 665 | mkdirSync(dirname(path), { recursive: true }); |
| 666 | if (existsSync(path)) { |
| 667 | try { |
| 668 | const stat = statSync(path); |
| 669 | if (Date.now() - stat.mtimeMs > DREAM_MARKER_STALE_MS) { |
| 670 | unlinkSync(path); |
| 671 | } else { |
| 672 | return false; |
| 673 | } |
| 674 | } catch { |
| 675 | return false; |
| 676 | } |
| 677 | } |
| 678 | const info: LockInfo = { pid: process.pid, started_at: new Date().toISOString() }; |
| 679 | try { |
| 680 | writeFileSync(path, JSON.stringify(info), { encoding: "utf-8", flag: "wx" }); |
| 681 | return true; |
| 682 | } catch { |
| 683 | return false; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | export function releaseDreamMarker(): void { |
| 688 | try { |
no test coverage detected