Skip to content

Commit

Permalink
returns LockedException on UPDATE & DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Nov 22, 2019
1 parent 89014e2 commit d9a37ca
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions lib/Storage/LockWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\Constants;
use OCP\Files\InvalidPathException;
use OCP\IUserSession;
use OCP\Lock\LockedException;

class LockWrapper extends Wrapper {
/** @var LockService */
Expand All @@ -40,21 +41,53 @@ public function __construct($arguments) {
$this->userSession = $arguments['user_session'];
}

protected function checkPermissions($path, $permissions) {

/**
* @param $path
* @param $permissions
*
* @return bool
* @throws LockedException
*/
protected function checkPermissions($path, $permissions): bool {
if (!$this->isLocked($path)) {
return true;
}

\OC::$server->getLogger()
->log(3, '---- ' . $permissions);
switch ($permissions) {
case Constants::PERMISSION_DELETE:
case Constants::PERMISSION_UPDATE:
throw new LockedException($path);

default:
return false;
}

}

/**
* @param $path
*
* @return bool
*/
protected function isLocked($path): bool {
try {
$user = $this->userSession->getUser();
$userId = '';
if ($user !== null) {
$userId = $user->getUID();
}

return !$this->lockService->isPathLocked($path, $userId);
return $this->lockService->isPathLocked($path, $userId);
} catch (InvalidPathException $e) {
}

return true;
return false;
}


public function rename($path1, $path2) {
if (strpos($path1, $path2) === 0) {
$part = substr($path1, strlen($path2));
Expand Down

0 comments on commit d9a37ca

Please sign in to comment.