MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / tryCreateExclusive

Function tryCreateExclusive

source code/utils/cronTasksLock.ts:66–93  ·  view source on GitHub ↗
(
  lock: SchedulerLock,
  dir?: string,
)

Source from the content-addressed store, hash-verified

64}
65
66async function tryCreateExclusive(
67 lock: SchedulerLock,
68 dir?: string,
69): Promise<boolean> {
70 const path = getLockPath(dir)
71 const body = jsonStringify(lock)
72 try {
73 await writeFile(path, body, { flag: 'wx' })
74 return true
75 } catch (e: unknown) {
76 const code = getErrnoCode(e)
77 if (code === 'EEXIST') return false
78 if (code === 'ENOENT') {
79 // .claude/ doesn't exist yet — create it and retry once. In steady
80 // state the dir already exists (scheduled_tasks.json lives there),
81 // so this path is hit at most once.
82 await mkdir(dirname(path), { recursive: true })
83 try {
84 await writeFile(path, body, { flag: 'wx' })
85 return true
86 } catch (retryErr: unknown) {
87 if (getErrnoCode(retryErr) === 'EEXIST') return false
88 throw retryErr
89 }
90 }
91 throw e
92 }
93}
94
95function registerLockCleanup(opts?: SchedulerLockOptions): void {
96 unregisterCleanup?.()

Callers 1

tryAcquireSchedulerLockFunction · 0.70

Calls 4

jsonStringifyFunction · 0.85
getErrnoCodeFunction · 0.85
mkdirFunction · 0.85
getLockPathFunction · 0.70

Tested by

no test coverage detected