summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-11-07 16:25:27 +0100
committerVincent Petry <pvince81@owncloud.com>2014-11-07 16:25:27 +0100
commitb6c868ec881f2b5eff856f76c7a58959930f3c6b (patch)
tree22fb9f1944b4d1aa3d94e1965317964f954ca012
parent32625aff3017ba183487d3688a620ce416b73408 (diff)
parent2db69a5328e9ec5f2ba36ab2a1545e2ea5e9c042 (diff)
downloadnextcloud-server-b6c868ec881f2b5eff856f76c7a58959930f3c6b.tar.gz
nextcloud-server-b6c868ec881f2b5eff856f76c7a58959930f3c6b.zip
Merge pull request #11994 from owncloud/stable7-sabre-convertstoragenotavailableexception
[stable7] Convert StorageNotAvailableException to SabreDAV exception
-rw-r--r--lib/private/connector/sabre/directory.php68
-rw-r--r--lib/private/connector/sabre/file.php138
-rw-r--r--lib/private/connector/sabre/objecttree.php58
-rw-r--r--lib/private/connector/sabre/quotaplugin.php8
4 files changed, 158 insertions, 114 deletions
diff --git a/lib/private/connector/sabre/directory.php b/lib/private/connector/sabre/directory.php
index 00807224c24..06e1d80031e 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'])) {
+
+ // 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();
+ } 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->fileView->isCreatable($this->path)) {
- throw new \Sabre\DAV\Exception\Forbidden();
- }
+ try {
+ if (!$this->fileView->isCreatable($this->path)) {
+ 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) {
diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php
index 13b33382165..64f05f75108 100644
--- a/lib/private/connector/sabre/file.php
+++ b/lib/private/connector/sabre/file.php
@@ -50,9 +50,13 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
* @return string|null
*/
public function put($data) {
- if ($this->info && $this->fileView->file_exists($this->path) &&
- !$this->info->isUpdateable()) {
- throw new \Sabre\DAV\Exception\Forbidden();
+ try {
+ if ($this->info && $this->fileView->file_exists($this->path) &&
+ !$this->info->isUpdateable()) {
+ throw new \Sabre\DAV\Exception\Forbidden();
+ }
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
// throw an exception if encryption was disabled but the files are still encrypted
@@ -100,42 +104,48 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
} catch (\OCP\Files\LockNotAcquiredException $e) {
// the file is currently being written to by another process
throw new OC_Connector_Sabre_Exception_FileLocked($e->getMessage(), $e->getCode(), $e);
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
- // double check if the file was fully received
- // compare expected and actual size
- if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] !== 'LOCK') {
- $expected = $_SERVER['CONTENT_LENGTH'];
- $actual = $this->fileView->filesize($partFilePath);
- if ($actual != $expected) {
- $this->fileView->unlink($partFilePath);
- throw new \Sabre\DAV\Exception\BadRequest('expected filesize ' . $expected . ' got ' . $actual);
+ try {
+ // double check if the file was fully received
+ // compare expected and actual size
+ if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] !== 'LOCK') {
+ $expected = $_SERVER['CONTENT_LENGTH'];
+ $actual = $this->fileView->filesize($partFilePath);
+ if ($actual != $expected) {
+ $this->fileView->unlink($partFilePath);
+ throw new \Sabre\DAV\Exception\BadRequest('expected filesize ' . $expected . ' got ' . $actual);
+ }
}
- }
- // rename to correct path
- try {
- $renameOkay = $this->fileView->rename($partFilePath, $this->path);
- $fileExists = $this->fileView->file_exists($this->path);
- if ($renameOkay === false || $fileExists === false) {
- \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
- $this->fileView->unlink($partFilePath);
- throw new \Sabre\DAV\Exception('Could not rename part file to final file');
+ // rename to correct path
+ try {
+ $renameOkay = $this->fileView->rename($partFilePath, $this->path);
+ $fileExists = $this->fileView->file_exists($this->path);
+ if ($renameOkay === false || $fileExists === false) {
+ \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
+ $this->fileView->unlink($partFilePath);
+ throw new \Sabre\DAV\Exception('Could not rename part file to final file');
+ }
+ }
+ catch (\OCP\Files\LockNotAcquiredException $e) {
+ // the file is currently being written to by another process
+ throw new OC_Connector_Sabre_Exception_FileLocked($e->getMessage(), $e->getCode(), $e);
}
- }
- catch (\OCP\Files\LockNotAcquiredException $e) {
- // the file is currently being written to by another process
- throw new OC_Connector_Sabre_Exception_FileLocked($e->getMessage(), $e->getCode(), $e);
- }
- // allow sync clients to send the mtime along in a header
- $mtime = OC_Request::hasModificationTime();
- if ($mtime !== false) {
- if($this->fileView->touch($this->path, $mtime)) {
- header('X-OC-MTime: accepted');
+ // allow sync clients to send the mtime along in a header
+ $mtime = OC_Request::hasModificationTime();
+ if ($mtime !== false) {
+ if($this->fileView->touch($this->path, $mtime)) {
+ header('X-OC-MTime: accepted');
+ }
}
+ $this->refreshInfo();
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
- $this->refreshInfo();
return '"' . $this->info->getEtag() . '"';
}
@@ -151,7 +161,11 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
if (\OC_Util::encryptedFiles()) {
throw new \Sabre\DAV\Exception\ServiceUnavailable();
} else {
- return $this->fileView->fopen(ltrim($this->path, '/'), 'rb');
+ try {
+ return $this->fileView->fopen(ltrim($this->path, '/'), 'rb');
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+ }
}
}
@@ -167,9 +181,13 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
throw new \Sabre\DAV\Exception\Forbidden();
}
- if (!$this->fileView->unlink($this->path)) {
- // assume it wasn't possible to delete due to permissions
- throw new \Sabre\DAV\Exception\Forbidden();
+ try {
+ if (!$this->fileView->unlink($this->path)) {
+ // assume it wasn't possible to delete due to permissions
+ throw new \Sabre\DAV\Exception\Forbidden();
+ }
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
// remove properties
@@ -243,33 +261,37 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
if ($chunk_handler->isComplete()) {
- // we first assembly the target file as a part file
- $partFile = $path . '/' . $info['name'] . '.ocTransferId' . $info['transferid'] . '.part';
- $chunk_handler->file_assemble($partFile);
-
- // here is the final atomic rename
- $targetPath = $path . '/' . $info['name'];
- $renameOkay = $this->fileView->rename($partFile, $targetPath);
- $fileExists = $this->fileView->file_exists($targetPath);
- if ($renameOkay === false || $fileExists === false) {
- \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
- // only delete if an error occurred and the target file was already created
- if ($fileExists) {
- $this->fileView->unlink($targetPath);
+ try {
+ // we first assembly the target file as a part file
+ $partFile = $path . '/' . $info['name'] . '.ocTransferId' . $info['transferid'] . '.part';
+ $chunk_handler->file_assemble($partFile);
+
+ // here is the final atomic rename
+ $targetPath = $path . '/' . $info['name'];
+ $renameOkay = $this->fileView->rename($partFile, $targetPath);
+ $fileExists = $this->fileView->file_exists($targetPath);
+ if ($renameOkay === false || $fileExists === false) {
+ \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
+ // only delete if an error occurred and the target file was already created
+ if ($fileExists) {
+ $this->fileView->unlink($targetPath);
+ }
+ throw new \Sabre\DAV\Exception('Could not rename part file assembled from chunks');
}
- throw new \Sabre\DAV\Exception('Could not rename part file assembled from chunks');
- }
- // allow sync clients to send the mtime along in a header
- $mtime = OC_Request::hasModificationTime();
- if ($mtime !== false) {
- if($this->fileView->touch($targetPath, $mtime)) {
- header('X-OC-MTime: accepted');
+ // allow sync clients to send the mtime along in a header
+ $mtime = OC_Request::hasModificationTime();
+ if ($mtime !== false) {
+ if($this->fileView->touch($targetPath, $mtime)) {
+ header('X-OC-MTime: accepted');
+ }
}
- }
- $info = $this->fileView->getFileInfo($targetPath);
- return $info->getEtag();
+ $info = $this->fileView->getFileInfo($targetPath);
+ return $info->getEtag();
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+ }
}
return null;
diff --git a/lib/private/connector/sabre/objecttree.php b/lib/private/connector/sabre/objecttree.php
index d7a96cfc88e..14a55b5cada 100644
--- a/lib/private/connector/sabre/objecttree.php
+++ b/lib/private/connector/sabre/objecttree.php
@@ -138,27 +138,31 @@ class ObjectTree extends \Sabre\DAV\ObjectTree {
$isMovableMount = true;
}
- // check update privileges
- if (!$this->fileView->isUpdatable($sourcePath) && !$isMovableMount) {
- throw new \Sabre\DAV\Exception\Forbidden();
- }
- if ($sourceDir !== $destinationDir) {
- if (!$this->fileView->isCreatable($destinationDir)) {
+ try {
+ // check update privileges
+ if (!$this->fileView->isUpdatable($sourcePath) && !$isMovableMount) {
throw new \Sabre\DAV\Exception\Forbidden();
}
- if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) {
- throw new \Sabre\DAV\Exception\Forbidden();
+ if ($sourceDir !== $destinationDir) {
+ if (!$this->fileView->isCreatable($destinationDir)) {
+ throw new \Sabre\DAV\Exception\Forbidden();
+ }
+ if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) {
+ throw new \Sabre\DAV\Exception\Forbidden();
+ }
}
- }
- $fileName = basename($destinationPath);
- if (!\OCP\Util::isValidFileName($fileName)) {
- throw new \Sabre\DAV\Exception\BadRequest();
- }
+ $fileName = basename($destinationPath);
+ if (!\OCP\Util::isValidFileName($fileName)) {
+ throw new \Sabre\DAV\Exception\BadRequest();
+ }
- $renameOkay = $this->fileView->rename($sourcePath, $destinationPath);
- if (!$renameOkay) {
- throw new \Sabre\DAV\Exception\Forbidden('');
+ $renameOkay = $this->fileView->rename($sourcePath, $destinationPath);
+ if (!$renameOkay) {
+ throw new \Sabre\DAV\Exception\Forbidden('');
+ }
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
// update properties
@@ -188,19 +192,23 @@ class ObjectTree extends \Sabre\DAV\ObjectTree {
throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
}
- if ($this->fileView->is_file($source)) {
- $this->fileView->copy($source, $destination);
- } else {
- $this->fileView->mkdir($destination);
- $dh = $this->fileView->opendir($source);
- if (is_resource($dh)) {
- while (($subNode = readdir($dh)) !== false) {
+ try {
+ if ($this->fileView->is_file($source)) {
+ $this->fileView->copy($source, $destination);
+ } else {
+ $this->fileView->mkdir($destination);
+ $dh = $this->fileView->opendir($source);
+ if (is_resource($dh)) {
+ while (($subNode = readdir($dh)) !== false) {
- if ($subNode == '.' || $subNode == '..') continue;
- $this->copy($source . '/' . $subNode, $destination . '/' . $subNode);
+ if ($subNode == '.' || $subNode == '..') continue;
+ $this->copy($source . '/' . $subNode, $destination . '/' . $subNode);
+ }
}
}
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
list($destinationDir,) = \Sabre\DAV\URLUtil::splitPath($destination);
diff --git a/lib/private/connector/sabre/quotaplugin.php b/lib/private/connector/sabre/quotaplugin.php
index cf3c1103f84..6dab64dad4a 100644
--- a/lib/private/connector/sabre/quotaplugin.php
+++ b/lib/private/connector/sabre/quotaplugin.php
@@ -102,7 +102,11 @@ class OC_Connector_Sabre_QuotaPlugin extends \Sabre\DAV\ServerPlugin {
* @return mixed
*/
public function getFreeSpace($parentUri) {
- $freeSpace = $this->view->free_space($parentUri);
- return $freeSpace;
+ try {
+ $freeSpace = $this->view->free_space($parentUri);
+ return $freeSpace;
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+ }
}
}