|
10 | 10 | namespace OCP\Lock; |
11 | 11 |
|
12 | 12 | /** |
13 | | - * This interface allows locking and unlocking filesystem paths |
| 13 | + * Contract for providers of shared and exclusive locks for server resources. |
14 | 14 | * |
15 | | - * This interface should be used directly and not implemented by an application. |
16 | | - * The implementation is provided by the server. |
| 15 | + * This low-level interface provides the short-lived locks used for concurrency |
| 16 | + * control by Nextcloud storage implementations and, through them, by the Files |
| 17 | + * Node and View APIs. |
| 18 | + * |
| 19 | + * While primarily used by storage implementations, this interface is generic |
| 20 | + * and may also coordinate access to other server resources. |
| 21 | + * |
| 22 | + * This is an underlying primitive, not the high-level VFS API used for locking |
| 23 | + * filesystem paths during normal Files Node or View operations. |
| 24 | + * |
| 25 | + * This interface is distinct from the OCP\Files\Lock APIs, which provide |
| 26 | + * user, application, and collaborative-editor locks for files. |
17 | 27 | * |
18 | 28 | * @since 8.1.0 |
19 | 29 | */ |
20 | 30 | interface ILockingProvider { |
21 | 31 | /** |
| 32 | + * A shared lock. Multiple shared locks may coexist, but they prevent an |
| 33 | + * exclusive lock from being acquired. |
| 34 | + * |
22 | 35 | * @since 8.1.0 |
23 | 36 | */ |
24 | 37 | public const LOCK_SHARED = 1; |
| 38 | + |
25 | 39 | /** |
| 40 | + * An exclusive lock. It prevents shared and exclusive locks from being |
| 41 | + * acquired. |
| 42 | + * |
26 | 43 | * @since 8.1.0 |
27 | 44 | */ |
28 | 45 | public const LOCK_EXCLUSIVE = 2; |
29 | 46 |
|
30 | 47 | /** |
31 | | - * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type |
| 48 | + * Check whether a lock of the requested type exists for a resource. |
| 49 | + * |
| 50 | + * This does not determine whether acquiring the requested type would |
| 51 | + * succeed. For example, an existing shared lock prevents an exclusive |
| 52 | + * acquisition, while this method returns false for LOCK_EXCLUSIVE. |
| 53 | + * |
| 54 | + * @param string $path Identifier of the resource to check. |
| 55 | + * @param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type Lock type to check. |
| 56 | + * @return bool True when a lock of the requested type exists. |
32 | 57 | * @since 8.1.0 |
33 | 58 | */ |
34 | 59 | public function isLocked(string $path, int $type): bool; |
35 | 60 |
|
36 | 61 | /** |
37 | | - * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type |
38 | | - * @param ?string $readablePath A human-readable path to use in error messages, since 20.0.0 |
39 | | - * @throws LockedException |
| 62 | + * Acquire a shared or exclusive lock for a resource. |
| 63 | + * |
| 64 | + * A shared lock cannot be acquired while an exclusive lock exists. An |
| 65 | + * exclusive lock cannot be acquired while any lock exists. |
| 66 | + * |
| 67 | + * @param string $path Identifier of the resource to lock. |
| 68 | + * @param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type Lock type to acquire. |
| 69 | + * @param ?string $readablePath Optional human-readable representation of |
| 70 | + * `$path` to include in error messages. |
| 71 | + * @throws LockedException If the requested lock cannot be acquired. |
40 | 72 | * @since 8.1.0 |
41 | 73 | */ |
42 | 74 | public function acquireLock(string $path, int $type, ?string $readablePath = null): void; |
43 | 75 |
|
44 | 76 | /** |
45 | | - * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type |
| 77 | + * Release one acquisition of the requested lock type for a resource. |
| 78 | + * |
| 79 | + * Repeated shared-lock acquisitions must be released separately. |
| 80 | + * |
| 81 | + * @param string $path Identifier of the resource to unlock. |
| 82 | + * @param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type Lock type to release. |
46 | 83 | * @since 8.1.0 |
47 | 84 | */ |
48 | 85 | public function releaseLock(string $path, int $type): void; |
49 | 86 |
|
50 | 87 | /** |
51 | | - * Change the target type of an existing lock |
| 88 | + * Convert an existing lock to another type. |
| 89 | + * |
| 90 | + * Converting a shared lock to an exclusive lock succeeds only when the |
| 91 | + * shared lock is the only shared lock. An exclusive lock can be converted |
| 92 | + * to a shared lock. |
52 | 93 | * |
53 | | - * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $targetType |
54 | | - * @throws LockedException |
| 94 | + * @param string $path Identifier of the resource whose lock to change. |
| 95 | + * @param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $targetType Lock type to |
| 96 | + * convert to. |
| 97 | + * @throws LockedException If the existing lock cannot be converted. |
55 | 98 | * @since 8.1.0 |
56 | 99 | */ |
57 | 100 | public function changeLock(string $path, int $targetType): void; |
58 | 101 |
|
59 | 102 | /** |
60 | | - * Release all lock acquired by this instance |
| 103 | + * Release all locks acquired and tracked by this provider instance. |
| 104 | + * |
61 | 105 | * @since 8.1.0 |
62 | 106 | */ |
63 | 107 | public function releaseAll(): void; |
|
0 commit comments