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