Merge pull request #12503 from nextcloud/swift-object-not-found-13

[13] forward object not found error in swift as dav 404
This commit is contained in:
Morris Jobke 2018-11-19 15:32:27 +01:00 committed by GitHub
commit 59b4643c72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View File

@ -50,6 +50,7 @@ use OCP\Files\ForbiddenException;
use OCP\Files\InvalidContentException; use OCP\Files\InvalidContentException;
use OCP\Files\InvalidPathException; use OCP\Files\InvalidPathException;
use OCP\Files\LockNotAcquiredException; use OCP\Files\LockNotAcquiredException;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException; use OCP\Files\NotPermittedException;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
@ -353,6 +354,8 @@ class File extends Node implements IFile {
throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry());
} catch (LockedException $e) { } catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e); throw new FileLocked($e->getMessage(), $e->getCode(), $e);
} catch (NotFoundException $e) {
throw new NotFound('File not found: ' . $e->getMessage(), $e->getCode(), $e);
} }
} }

View File

@ -28,6 +28,8 @@ namespace OC\Files\ObjectStore;
use Icewind\Streams\CallbackWrapper; use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory; use Icewind\Streams\IteratorDirectory;
use OC\Files\Cache\CacheEntry; use OC\Files\Cache\CacheEntry;
use OC\Files\Stream\CountReadStream;
use OCP\Files\NotFoundException;
use OCP\Files\ObjectStore\IObjectStore; use OCP\Files\ObjectStore\IObjectStore;
class ObjectStoreStorage extends \OC\Files\Storage\Common { class ObjectStoreStorage extends \OC\Files\Storage\Common {
@ -269,10 +271,16 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
if (is_array($stat)) { if (is_array($stat)) {
try { try {
return $this->objectStore->readObject($this->getURN($stat['fileid'])); 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) { } catch (\Exception $ex) {
$this->logger->logException($ex, [ $this->logger->logException($ex, [
'app' => 'objectstore', '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; return false;
} }

View File

@ -27,12 +27,14 @@ namespace OC\Files\ObjectStore;
use Guzzle\Http\Exception\ClientErrorResponseException; use Guzzle\Http\Exception\ClientErrorResponseException;
use Icewind\Streams\RetryWrapper; use Icewind\Streams\RetryWrapper;
use OCP\Files\NotFoundException;
use OCP\Files\ObjectStore\IObjectStore; use OCP\Files\ObjectStore\IObjectStore;
use OCP\Files\StorageAuthException; use OCP\Files\StorageAuthException;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OpenCloud\Common\Service\Catalog; use OpenCloud\Common\Service\Catalog;
use OpenCloud\Common\Service\CatalogItem; use OpenCloud\Common\Service\CatalogItem;
use OpenCloud\Identity\Resource\Token; use OpenCloud\Identity\Resource\Token;
use OpenCloud\ObjectStore\Exception\ObjectNotFoundException;
use OpenCloud\ObjectStore\Service; use OpenCloud\ObjectStore\Service;
use OpenCloud\OpenStack; use OpenCloud\OpenStack;
use OpenCloud\Rackspace; use OpenCloud\Rackspace;
@ -252,13 +254,17 @@ class Swift implements IObjectStore {
* @throws Exception from openstack lib when something goes wrong * @throws Exception from openstack lib when something goes wrong
*/ */
public function readObject($urn) { public function readObject($urn) {
$this->init(); try {
$object = $this->container->getObject($urn); $this->init();
$object = $this->container->getObject($urn);
// we need to keep a reference to objectContent or // we need to keep a reference to objectContent or
// the stream will be closed before we can do anything with it // the stream will be closed before we can do anything with it
/** @var $objectContent \Guzzle\Http\EntityBody * */ /** @var $objectContent \Guzzle\Http\EntityBody * */
$objectContent = $object->getContent(); $objectContent = $object->getContent();
} catch (ObjectNotFoundException $e) {
throw new NotFoundException("object $urn not found in object store");
}
$objectContent->rewind(); $objectContent->rewind();
$stream = $objectContent->getStream(); $stream = $objectContent->getStream();