MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / createServeLock

Function createServeLock

src/cli.ts:741–776  ·  view source on GitHub ↗
(lockPath: string)

Source from the content-addressed store, hash-verified

739}
740
741async function createServeLock(lockPath: string): Promise<ServeLock> {
742 const handle = await fsp.open(lockPath, 'wx');
743 const payload: ServeLockPayload = {
744 pid: process.pid,
745 startedAt: new Date().toISOString(),
746 cwd: process.cwd(),
747 };
748 await handle.writeFile(`${JSON.stringify(payload, null, 2)}\n`, 'utf8');
749 let released = false;
750
751 return {
752 lockPath,
753 async release() {
754 if (released) {
755 return;
756 }
757 released = true;
758 try {
759 await handle.close();
760 } catch {}
761 await fsp.rm(lockPath, { force: true });
762 },
763 releaseSync() {
764 if (released) {
765 return;
766 }
767 released = true;
768 try {
769 handle.close().catch(() => {});
770 } catch {}
771 try {
772 fs.rmSync(lockPath, { force: true });
773 } catch {}
774 },
775 };
776}
777
778function readServeLock(lockPath: string): ServeLockPayload | null {
779 if (!fs.existsSync(lockPath)) {

Callers 1

acquireServeLockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected