MCPcopy Index your code
hub / github.com/codeaashu/claude-code / tryCreateExclusive

Function tryCreateExclusive

src/utils/cronTasksLock.ts:64–91  ·  view source on GitHub ↗
(
  lock: SchedulerLock,
  dir?: string,
)

Source from the content-addressed store, hash-verified

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