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

Function acquireLock

scripts/update.js:30–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28}
29
30function 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
53function releaseLock() {
54 try {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected