(userId: string, path: string, presentedTokens: string[])
| 38 | |
| 39 | // A lock on any ancestor collection with Depth: infinity covers this path too. |
| 40 | export function findBlockingLock(userId: string, path: string, presentedTokens: string[]): WebDavLock | null { |
| 41 | const exactLock = locksByKey.get(buildKey(userId, path)); |
| 42 | |
| 43 | if (exactLock && !isExpired(exactLock) && !presentedTokens.includes(exactLock.token)) { |
| 44 | return exactLock; |
| 45 | } |
| 46 | |
| 47 | for (const ancestorPath of getAncestorPaths(path)) { |
| 48 | const ancestorLock = locksByKey.get(buildKey(userId, ancestorPath)); |
| 49 | |
| 50 | if ( |
| 51 | ancestorLock && ancestorLock.depth === 'infinity' && !isExpired(ancestorLock) && |
| 52 | !presentedTokens.includes(ancestorLock.token) |
| 53 | ) { |
| 54 | return ancestorLock; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return null; |
| 59 | } |
| 60 | |
| 61 | export function acquireLock(userId: string, path: string, depth: 'infinity' | '0'): { token: string } | null { |
| 62 | if (findBlockingLock(userId, path, [])) { |
no test coverage detected