Merge pull request #12500 from nextcloud/swift-object-not-found
forward object not found error in swift as dav 404
This commit is contained in:
commit
8e65f08617
|
@ -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\Storage;
|
use OCP\Files\Storage;
|
||||||
use OCP\Files\StorageNotAvailableException;
|
use OCP\Files\StorageNotAvailableException;
|
||||||
|
@ -592,6 +593,9 @@ class File extends Node implements IFile {
|
||||||
if ($e instanceof StorageNotAvailableException) {
|
if ($e instanceof StorageNotAvailableException) {
|
||||||
throw new ServiceUnavailable('Failed to write file contents: ' . $e->getMessage(), 0, $e);
|
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);
|
throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ 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 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 {
|
||||||
|
@ -275,10 +276,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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,10 @@ namespace OC\Files\ObjectStore;
|
||||||
|
|
||||||
use function GuzzleHttp\Psr7\stream_for;
|
use function GuzzleHttp\Psr7\stream_for;
|
||||||
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 OpenStack\Common\Error\BadResponseError;
|
||||||
|
|
||||||
class Swift implements IObjectStore {
|
class Swift implements IObjectStore {
|
||||||
/**
|
/**
|
||||||
|
@ -84,13 +86,22 @@ class Swift implements IObjectStore {
|
||||||
* @param string $urn the unified resource name used to identify the object
|
* @param string $urn the unified resource name used to identify the object
|
||||||
* @return resource stream with the read data
|
* @return resource stream with the read data
|
||||||
* @throws \Exception from openstack lib when something goes wrong
|
* @throws \Exception from openstack lib when something goes wrong
|
||||||
|
* @throws NotFoundException if file does not exist
|
||||||
*/
|
*/
|
||||||
public function readObject($urn) {
|
public function readObject($urn) {
|
||||||
$object = $this->getContainer()->getObject($urn);
|
try {
|
||||||
|
$object = $this->getContainer()->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
|
||||||
$objectContent = $object->download();
|
$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();
|
$objectContent->rewind();
|
||||||
|
|
||||||
$stream = $objectContent->detach();
|
$stream = $objectContent->detach();
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
*/
|
*/
|
||||||
namespace OCP\Files\ObjectStore;
|
namespace OCP\Files\ObjectStore;
|
||||||
|
|
||||||
|
use OCP\Files\NotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface IObjectStore
|
* Interface IObjectStore
|
||||||
*
|
*
|
||||||
|
@ -41,6 +43,7 @@ interface IObjectStore {
|
||||||
* @param string $urn the unified resource name used to identify the object
|
* @param string $urn the unified resource name used to identify the object
|
||||||
* @return resource stream with the read data
|
* @return resource stream with the read data
|
||||||
* @throws \Exception when something goes wrong, message will be logged
|
* @throws \Exception when something goes wrong, message will be logged
|
||||||
|
* @throws NotFoundException if file does not exist
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
*/
|
*/
|
||||||
public function readObject($urn);
|
public function readObject($urn);
|
||||||
|
|
Loading…
Reference in New Issue