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

Function acquireLock

scripts/update.js:34–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32}
33
34function 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
57function releaseLock() {
58 try {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected