Convert LockedException to FileLocked in Sabre connector

For Sabre to be able to return the proper error code instead of 500, the
LockedException is now rethrown as FileLocked exception in the Sabre
connector
This commit is contained in:
Vincent Petry 2015-05-29 09:59:20 +02:00 committed by Robin Appelman
parent 8665a98744
commit ba174ac626
2 changed files with 19 additions and 3 deletions

View File

@ -46,6 +46,7 @@ use OCP\Files\LockNotAcquiredException;
use OCP\Files\NotPermittedException; use OCP\Files\NotPermittedException;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use Sabre\DAV\Exception; use Sabre\DAV\Exception;
use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Forbidden;
@ -80,6 +81,7 @@ class File extends Node implements IFile {
* @throws Exception * @throws Exception
* @throws EntityTooLarge * @throws EntityTooLarge
* @throws ServiceUnavailable * @throws ServiceUnavailable
* @throws FileLocked
* @return string|null * @return string|null
*/ */
public function put($data) { public function put($data) {
@ -111,7 +113,11 @@ class File extends Node implements IFile {
$partFilePath = $this->path; $partFilePath = $this->path;
} }
$this->fileView->lockFile($this->path, ILockingProvider::LOCK_EXCLUSIVE); try {
$this->fileView->lockFile($this->path, ILockingProvider::LOCK_EXCLUSIVE);
} catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
}
// the part file and target file might be on a different storage in case of a single file storage (e.g. single file share) // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share)
/** @var \OC\Files\Storage\Storage $partStorage */ /** @var \OC\Files\Storage\Storage $partStorage */
@ -257,6 +263,8 @@ class File extends Node implements IFile {
throw new ServiceUnavailable("Encryption not ready: " . $e->getMessage()); throw new ServiceUnavailable("Encryption not ready: " . $e->getMessage());
} catch (StorageNotAvailableException $e) { } catch (StorageNotAvailableException $e) {
throw new ServiceUnavailable("Failed to open file: " . $e->getMessage()); throw new ServiceUnavailable("Failed to open file: " . $e->getMessage());
} catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
} }
} }
@ -278,6 +286,8 @@ class File extends Node implements IFile {
} }
} catch (StorageNotAvailableException $e) { } catch (StorageNotAvailableException $e) {
throw new ServiceUnavailable("Failed to unlink: " . $e->getMessage()); throw new ServiceUnavailable("Failed to unlink: " . $e->getMessage());
} catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
} }
} }
@ -383,6 +393,8 @@ class File extends Node implements IFile {
return $info->getEtag(); return $info->getEtag();
} catch (StorageNotAvailableException $e) { } catch (StorageNotAvailableException $e) {
throw new ServiceUnavailable("Failed to put file: " . $e->getMessage()); throw new ServiceUnavailable("Failed to put file: " . $e->getMessage());
} catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
} }
} }

View File

@ -26,10 +26,12 @@
namespace OC\Connector\Sabre; namespace OC\Connector\Sabre;
use OC\Connector\Sabre\Exception\InvalidPath; use OC\Connector\Sabre\Exception\InvalidPath;
use OC\Connector\Sabre\Exception\FileLocked;
use OC\Files\FileInfo; use OC\Files\FileInfo;
use OC\Files\Mount\MoveableMount; use OC\Files\Mount\MoveableMount;
use OCP\Files\StorageInvalidException; use OCP\Files\StorageInvalidException;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\Lock\LockedException;
class ObjectTree extends \Sabre\DAV\Tree { class ObjectTree extends \Sabre\DAV\Tree {
@ -221,8 +223,10 @@ class ObjectTree extends \Sabre\DAV\Tree {
if (!$renameOkay) { if (!$renameOkay) {
throw new \Sabre\DAV\Exception\Forbidden(''); throw new \Sabre\DAV\Exception\Forbidden('');
} }
} catch (\OCP\Files\StorageNotAvailableException $e) { } catch (StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
} catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
} }
$this->markDirty($sourceDir); $this->markDirty($sourceDir);
@ -258,7 +262,7 @@ class ObjectTree extends \Sabre\DAV\Tree {
try { try {
$this->fileView->copy($source, $destination); $this->fileView->copy($source, $destination);
} catch (\OCP\Files\StorageNotAvailableException $e) { } catch (StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
} }