Merge pull request #22812 from owncloud/node-lock
Add locking to the node api
This commit is contained in:
commit
fa436b5b0c
|
@ -356,4 +356,28 @@ class Node implements \OCP\Files\Node {
|
||||||
public function getChecksum() {
|
public function getChecksum() {
|
||||||
return;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,4 +225,55 @@ interface Node extends FileInfo {
|
||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
public function getName();
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue