summaryrefslogtreecommitdiffstats
path: root/lib/private/connector/sabre/directory.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-11-06 10:59:36 +0100
committerVincent Petry <pvince81@owncloud.com>2014-11-10 12:01:24 +0100
commitcccedf6f30b74cc2eafc4b5000fb3dd442b0093f (patch)
treeda645007733143ede51d255ccaf9b334587cb043 /lib/private/connector/sabre/directory.php
parent0d00e247c374318d502cb0501fce3093320fa5a3 (diff)
downloadnextcloud-server-cccedf6f30b74cc2eafc4b5000fb3dd442b0093f.tar.gz
nextcloud-server-cccedf6f30b74cc2eafc4b5000fb3dd442b0093f.zip
Convert StorageNotAvailableException to SabreDAV exception
Convert \OCP\Files\StorageNotAvailableException to \Sabre\DAV\Exception\ServiceUnavailable for every file/directory operation happening inside of SabreDAV. This is necessary to avoid having the exception bubble up to remote.php which would return an exception page instead of an appropriate response.
Diffstat (limited to 'lib/private/connector/sabre/directory.php')
-rw-r--r--lib/private/connector/sabre/directory.php68
1 files changed, 39 insertions, 29 deletions
diff --git a/lib/private/connector/sabre/directory.php b/lib/private/connector/sabre/directory.php
index 0d35c7d528e..ec5f82f9daa 100644
--- a/lib/private/connector/sabre/directory.php
+++ b/lib/private/connector/sabre/directory.php
@@ -51,29 +51,33 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node
*/
public function createFile($name, $data = null) {
- // for chunked upload also updating a existing file is a "createFile"
- // because we create all the chunks before re-assemble them to the existing file.
- if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
-
- // exit if we can't create a new file and we don't updatable existing file
- $info = OC_FileChunking::decodeName($name);
- if (!$this->fileView->isCreatable($this->path) &&
- !$this->fileView->isUpdatable($this->path . '/' . $info['name'])) {
- throw new \Sabre\DAV\Exception\Forbidden();
- }
+ try {
+ // for chunked upload also updating a existing file is a "createFile"
+ // because we create all the chunks before re-assemble them to the existing file.
+ if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
- } else {
- // For non-chunked upload it is enough to check if we can create a new file
- if (!$this->fileView->isCreatable($this->path)) {
- throw new \Sabre\DAV\Exception\Forbidden();
+ // exit if we can't create a new file and we don't updatable existing file
+ $info = OC_FileChunking::decodeName($name);
+ if (!$this->fileView->isCreatable($this->path) &&
+ !$this->fileView->isUpdatable($this->path . '/' . $info['name'])) {
+ throw new \Sabre\DAV\Exception\Forbidden();
+ }
+
+ } else {
+ // For non-chunked upload it is enough to check if we can create a new file
+ if (!$this->fileView->isCreatable($this->path)) {
+ throw new \Sabre\DAV\Exception\Forbidden();
+ }
}
- }
- $path = $this->fileView->getAbsolutePath($this->path) . '/' . $name;
- // using a dummy FileInfo is acceptable here since it will be refreshed after the put is complete
- $info = new \OC\Files\FileInfo($path, null, null, array());
- $node = new OC_Connector_Sabre_File($this->fileView, $info);
- return $node->put($data);
+ $path = $this->fileView->getAbsolutePath($this->path) . '/' . $name;
+ // using a dummy FileInfo is acceptable here since it will be refreshed after the put is complete
+ $info = new \OC\Files\FileInfo($path, null, null, array());
+ $node = new OC_Connector_Sabre_File($this->fileView, $info);
+ return $node->put($data);
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+ }
}
/**
@@ -84,15 +88,18 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node
* @return void
*/
public function createDirectory($name) {
- if (!$this->info->isCreatable()) {
- throw new \Sabre\DAV\Exception\Forbidden();
- }
+ try {
+ if (!$this->info->isCreatable()) {
+ throw new \Sabre\DAV\Exception\Forbidden();
+ }
- $newPath = $this->path . '/' . $name;
- if(!$this->fileView->mkdir($newPath)) {
- throw new \Sabre\DAV\Exception\Forbidden('Could not create directory '.$newPath);
+ $newPath = $this->path . '/' . $name;
+ if(!$this->fileView->mkdir($newPath)) {
+ throw new \Sabre\DAV\Exception\Forbidden('Could not create directory '.$newPath);
+ }
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
-
}
/**
@@ -104,10 +111,13 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node
* @return \Sabre\DAV\INode
*/
public function getChild($name, $info = null) {
-
$path = $this->path . '/' . $name;
if (is_null($info)) {
- $info = $this->fileView->getFileInfo($path);
+ try {
+ $info = $this->fileView->getFileInfo($path);
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+ }
}
if (!$info) {