Merge pull request #12072 from owncloud/sabre-convertstoragenotavailableexception-secondtry

Convert StorageNotAvailableException to SabreDAV exception
This commit is contained in:
Vincent Petry 2014-11-10 12:52:52 +01:00
commit 9b99c1d6f0
4 changed files with 155 additions and 113 deletions

View File

@ -51,6 +51,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node
*/
public function createFile($name, $data = null) {
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'])) {
@ -74,6 +75,9 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node
$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,6 +88,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node
* @return void
*/
public function createDirectory($name) {
try {
if (!$this->info->isCreatable()) {
throw new \Sabre\DAV\Exception\Forbidden();
}
@ -92,7 +97,9 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node
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)) {
try {
$info = $this->fileView->getFileInfo($path);
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
}
if (!$info) {

View File

@ -50,10 +50,14 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
* @return string|null
*/
public function put($data) {
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
if (\OC_Util::encryptedFiles()) {
@ -102,8 +106,11 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
throw new OC_Connector_Sabre_Exception_FileLocked($e->getMessage(), $e->getCode(), $e);
} catch (\OCA\Encryption\Exception\EncryptionException $e) {
throw new \Sabre\DAV\Exception\Forbidden($e->getMessage());
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
try {
// if content length is sent by client:
// double check if the file was fully received
// compare expected and actual size
@ -139,6 +146,9 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
}
}
$this->refreshInfo();
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
return '"' . $this->info->getEtag() . '"';
}
@ -158,6 +168,8 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
return $this->fileView->fopen(ltrim($this->path, '/'), 'rb');
} catch (\OCA\Encryption\Exception\EncryptionException $e) {
throw new \Sabre\DAV\Exception\Forbidden($e->getMessage());
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
}
@ -174,10 +186,14 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
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
$this->removeProperties();
@ -235,6 +251,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
if ($chunk_handler->isComplete()) {
try {
// we first assembly the target file as a part file
$partFile = $path . '/' . $info['name'] . '.ocTransferId' . $info['transferid'] . '.part';
$chunk_handler->file_assemble($partFile);
@ -262,6 +279,9 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
$info = $this->fileView->getFileInfo($targetPath);
return $info->getEtag();
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
}
return null;

View File

@ -138,6 +138,7 @@ class ObjectTree extends \Sabre\DAV\ObjectTree {
$isMovableMount = true;
}
try {
// check update privileges
if (!$this->fileView->isUpdatable($sourcePath) && !$isMovableMount) {
throw new \Sabre\DAV\Exception\Forbidden();
@ -160,6 +161,9 @@ class ObjectTree extends \Sabre\DAV\ObjectTree {
if (!$renameOkay) {
throw new \Sabre\DAV\Exception\Forbidden('');
}
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
// update properties
$query = \OC_DB::prepare('UPDATE `*PREFIX*properties` SET `propertypath` = ?'
@ -188,6 +192,7 @@ class ObjectTree extends \Sabre\DAV\ObjectTree {
throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
}
try {
if ($this->fileView->is_file($source)) {
$this->fileView->copy($source, $destination);
} else {
@ -202,6 +207,9 @@ class ObjectTree extends \Sabre\DAV\ObjectTree {
}
}
}
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
list($destinationDir,) = \Sabre\DAV\URLUtil::splitPath($destination);
$this->markDirty($destinationDir);

View File

@ -102,7 +102,11 @@ class OC_Connector_Sabre_QuotaPlugin extends \Sabre\DAV\ServerPlugin {
* @return mixed
*/
public function getFreeSpace($parentUri) {
try {
$freeSpace = $this->view->free_space($parentUri);
return $freeSpace;
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
}
}