aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2016-03-03 13:45:48 +0100
committerRobin Appelman <icewind@owncloud.com>2016-03-03 13:47:00 +0100
commit02635c6f2fe9357c88aa896896aec036f92c8d87 (patch)
tree9abaf104c113522c7a290dae9c490fe9510d8175 /lib
parent4f25f341788b3edad1bf4baf739cd632785c9abb (diff)
downloadnextcloud-server-02635c6f2fe9357c88aa896896aec036f92c8d87.tar.gz
nextcloud-server-02635c6f2fe9357c88aa896896aec036f92c8d87.zip
Add locking to the node api
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/node/node.php24
-rw-r--r--lib/public/files/node.php51
2 files changed, 75 insertions, 0 deletions
diff --git a/lib/private/files/node/node.php b/lib/private/files/node/node.php
index 5df4f738a42..c4fabfc2e2e 100644
--- a/lib/private/files/node/node.php
+++ b/lib/private/files/node/node.php
@@ -356,4 +356,28 @@ class Node implements \OCP\Files\Node {
public function getChecksum() {
return;
}
+
+ /**
+ * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
+ * @throws \OCP\Lock\LockedException
+ */
+ public function lock($type) {
+ $this->view->lockFile($this->path, $type);
+ }
+
+ /**
+ * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
+ * @throws \OCP\Lock\LockedException
+ */
+ public function changeLock($type) {
+ $this->view->changeLock($this->path, $type);
+ }
+
+ /**
+ * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
+ * @throws \OCP\Lock\LockedException
+ */
+ public function unlock($type) {
+ $this->view->unlockFile($this->path, $type);
+ }
}
diff --git a/lib/public/files/node.php b/lib/public/files/node.php
index ee3f0cb0413..c69077c7f2a 100644
--- a/lib/public/files/node.php
+++ b/lib/public/files/node.php
@@ -225,4 +225,55 @@ interface Node extends FileInfo {
* @since 6.0.0
*/
public function getName();
+
+ /**
+ * Acquire a lock on this file or folder.
+ *
+ * A shared (read) lock will prevent any exclusive (write) locks from being created but any number of shared locks
+ * can be active at the same time.
+ * An exclusive lock will prevent any other lock from being created (both shared and exclusive).
+ *
+ * A locked exception will be thrown if any conflicting lock already exists
+ *
+ * Note that this uses mandatory locking, if you acquire an exclusive lock on a file it will block *all*
+ * other operations for that file, even within the same php process.
+ *
+ * Acquiring any lock on a file will also create a shared lock on all parent folders of that file.
+ *
+ * Note that in most cases you won't need to manually manage the locks for any files you're working with,
+ * any filesystem operation will automatically acquire the relevant locks for that operation.
+ *
+ * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
+ * @throws \OCP\Lock\LockedException
+ * @since 9.1.0
+ */
+ public function lock($type);
+
+ /**
+ * Check the type of an existing lock.
+ *
+ * A shared lock can be changed to an exclusive lock is there is exactly one shared lock on the file,
+ * an exclusive lock can always be changed to a shared lock since there can only be one exclusive lock int he first place.
+ *
+ * A locked exception will be thrown when these preconditions are not met.
+ * Note that this is also the case if no existing lock exists for the file.
+ *
+ * @param int $targetType \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
+ * @throws \OCP\Lock\LockedException
+ * @since 9.1.0
+ */
+ public function changeLock($targetType);
+
+ /**
+ * Release an existing lock.
+ *
+ * This will also free up the shared locks on any parent folder that were automatically acquired when locking the file.
+ *
+ * Note that this method will not give any sort of error when trying to free a lock that doesn't exist.
+ *
+ * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
+ * @throws \OCP\Lock\LockedException
+ * @since 9.1.0
+ */
+ public function unlock($type);
}