Skip to content

Commit

Permalink
forward object not found error in switch as dav 404
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Nov 16, 2018
1 parent a4d81ba commit 55c1f70
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use OCP\Files\InvalidContentException;
use OCP\Files\InvalidPathException;
use OCP\Files\LockNotAcquiredException;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage;
use OCP\Files\StorageNotAvailableException;
Expand Down Expand Up @@ -592,6 +593,9 @@ private function convertToSabreException(\Exception $e) {
if ($e instanceof StorageNotAvailableException) {
throw new ServiceUnavailable('Failed to write file contents: ' . $e->getMessage(), 0, $e);
}
if ($e instanceof NotFoundException) {
throw new NotFound('File not found: ' . $e->getMessage(), 0, $e);
}

throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Icewind\Streams\IteratorDirectory;
use OC\Files\Cache\CacheEntry;
use OC\Files\Stream\CountReadStream;
use OCP\Files\NotFoundException;
use OCP\Files\ObjectStore\IObjectStore;

class ObjectStoreStorage extends \OC\Files\Storage\Common {
Expand Down Expand Up @@ -275,6 +276,12 @@ public function fopen($path, $mode) {
if (is_array($stat)) {
try {
return $this->objectStore->readObject($this->getURN($stat['fileid']));
} catch (NotFoundException $e) {
$this->logger->logException($e, [
'app' => 'objectstore',
'message' => 'Count not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
]);
throw $e;
} catch (\Exception $ex) {
$this->logger->logException($ex, [
'app' => 'objectstore',
Expand Down
20 changes: 15 additions & 5 deletions lib/private/Files/ObjectStore/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@

use function GuzzleHttp\Psr7\stream_for;
use Icewind\Streams\RetryWrapper;
use OCP\Files\NotFoundException;
use OCP\Files\ObjectStore\IObjectStore;
use OCP\Files\StorageAuthException;
use OpenStack\Common\Error\BadResponseError;

class Swift implements IObjectStore {
/**
Expand Down Expand Up @@ -86,11 +88,19 @@ public function writeObject($urn, $stream) {
* @throws \Exception from openstack lib when something goes wrong
*/
public function readObject($urn) {
$object = $this->getContainer()->getObject($urn);

// we need to keep a reference to objectContent or
// the stream will be closed before we can do anything with it
$objectContent = $object->download();
try {
$object = $this->getContainer()->getObject($urn);

// we need to keep a reference to objectContent or
// the stream will be closed before we can do anything with it
$objectContent = $object->download();
} catch (BadResponseError $e) {
if ($e->getResponse()->getStatusCode() === 404) {
throw new NotFoundException("object $urn not found in object store");
} else {
throw $e;
}
}
$objectContent->rewind();

$stream = $objectContent->detach();
Expand Down

0 comments on commit 55c1f70

Please sign in to comment.