| 32 | } |
| 33 | |
| 34 | function acquireLock() { |
| 35 | fs.mkdirSync(stateDir, { recursive: true }); |
| 36 | try { |
| 37 | fs.writeFileSync(lockFile, String(process.pid), { flag: "wx" }); |
| 38 | return true; |
| 39 | } catch (e) { |
| 40 | if (e.code !== "EEXIST") return false; |
| 41 | try { |
| 42 | const pid = parseInt(fs.readFileSync(lockFile, "utf8").trim(), 10); |
| 43 | process.kill(pid, 0); |
| 44 | return false; |
| 45 | } catch (_) { |
| 46 | try { |
| 47 | fs.unlinkSync(lockFile); |
| 48 | fs.writeFileSync(lockFile, String(process.pid), { flag: "wx" }); |
| 49 | return true; |
| 50 | } catch (_2) { |
| 51 | return false; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | function releaseLock() { |
| 58 | try { |