MCPcopy Create free account
hub / github.com/alibaba/open-code-review / acquireLock

Function acquireLock

scripts/update.js:35–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected