(userId: string, path: string, depth: 'infinity' | '0')
| 59 | } |
| 60 | |
| 61 | export function acquireLock(userId: string, path: string, depth: 'infinity' | '0'): { token: string } | null { |
| 62 | if (findBlockingLock(userId, path, [])) { |
| 63 | return null; |
| 64 | } |
| 65 | |
| 66 | if (depth === 'infinity' && hasDescendantLock(userId, path)) { |
| 67 | return null; |
| 68 | } |
| 69 | |
| 70 | const token = `opaquelocktoken:${crypto.randomUUID()}`; |
| 71 | |
| 72 | locksByKey.set(buildKey(userId, path), { |
| 73 | token, |
| 74 | path, |
| 75 | depth, |
| 76 | expiresAt: new Date(Date.now() + LOCK_TIMEOUT_IN_MILLISECONDS), |
| 77 | }); |
| 78 | |
| 79 | return { token }; |
| 80 | } |
| 81 | |
| 82 | // A lock can be refreshed via a member URI too (e.g. a file inside a Depth: infinity-locked collection). |
| 83 | export function refreshLock( |
no test coverage detected