]> source.dussan.org Git - nextcloud-server.git/commitdiff
forward object not found error in swift as dav 404 12502/head
authorRobin Appelman <robin@icewind.nl>
Fri, 16 Nov 2018 19:21:21 +0000 (20:21 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Mon, 19 Nov 2018 10:36:33 +0000 (11:36 +0100)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/dav/lib/Connector/Sabre/File.php
lib/private/Files/ObjectStore/ObjectStoreStorage.php
lib/private/Files/ObjectStore/Swift.php

index 9e927ff85e5bf5182e41bdcdd2c095ae0cf36cbf..66400c958579a7c20c7054f4d5c1e0aff93d5e0d 100644 (file)
@@ -50,6 +50,7 @@ use OCP\Files\ForbiddenException;
 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;
@@ -583,6 +584,9 @@ class File extends Node implements IFile {
                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);
        }
index 3ce919a4cbe709de05f96d7c80496437abd1c8fc..d8649129d9034f8df4655c8bee93377d3988081d 100644 (file)
@@ -28,6 +28,8 @@ namespace OC\Files\ObjectStore;
 use Icewind\Streams\CallbackWrapper;
 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 {
@@ -274,10 +276,16 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
                                if (is_array($stat)) {
                                        try {
                                                return $this->objectStore->readObject($this->getURN($stat['fileid']));
+                                       } catch (NotFoundException $e) {
+                                               $this->logger->logException($e, [
+                                                       'app' => 'objectstore',
+                                                       'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
+                                               ]);
+                                               throw $e;
                                        } catch (\Exception $ex) {
                                                $this->logger->logException($ex, [
                                                        'app' => 'objectstore',
-                                                       'message' => 'Count not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
+                                                       'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
                                                ]);
                                                return false;
                                        }
index 6bb01506c4c214c13a32536f37df4a8695d03e3a..667b92bd1d66bf842eff4b48697d702179164aae 100644 (file)
@@ -27,8 +27,10 @@ namespace OC\Files\ObjectStore;
 
 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 {
        /**
@@ -86,11 +88,19 @@ class Swift implements IObjectStore {
         * @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();