Skip to content

Commit 05fddcd

Browse files
icewind1991MorrisJobke
authored andcommitted
forward object not found error in swift as dav 404
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent e2c819f commit 05fddcd

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

apps/dav/lib/Connector/Sabre/File.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use OCP\Files\InvalidContentException;
4545
use OCP\Files\InvalidPathException;
4646
use OCP\Files\LockNotAcquiredException;
47+
use OCP\Files\NotFoundException;
4748
use OCP\Files\NotPermittedException;
4849
use OCP\Files\StorageNotAvailableException;
4950
use OCP\Lock\ILockingProvider;
@@ -324,6 +325,8 @@ public function get() {
324325
throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry());
325326
} catch (LockedException $e) {
326327
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
328+
} catch (NotFoundException $e) {
329+
throw new NotFound('File not found: ' . $e->getMessage(), $e->getCode(), $e);
327330
}
328331
}
329332

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
use Icewind\Streams\CallbackWrapper;
2929
use Icewind\Streams\IteratorDirectory;
3030
use OC\Files\Cache\CacheEntry;
31+
use OC\Files\Stream\CountReadStream;
32+
use OCP\Files\NotFoundException;
3133
use OCP\Files\ObjectStore\IObjectStore;
3234

3335
class ObjectStoreStorage extends \OC\Files\Storage\Common {
@@ -269,10 +271,16 @@ public function fopen($path, $mode) {
269271
if (is_array($stat)) {
270272
try {
271273
return $this->objectStore->readObject($this->getURN($stat['fileid']));
274+
} catch (NotFoundException $e) {
275+
$this->logger->logException($e, [
276+
'app' => 'objectstore',
277+
'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
278+
]);
279+
throw $e;
272280
} catch (\Exception $ex) {
273281
$this->logger->logException($ex, [
274282
'app' => 'objectstore',
275-
'message' => 'Count not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
283+
'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
276284
]);
277285
return false;
278286
}

lib/private/Files/ObjectStore/Swift.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626

2727
use Guzzle\Http\Exception\ClientErrorResponseException;
2828
use Icewind\Streams\RetryWrapper;
29+
use OCP\Files\NotFoundException;
2930
use OCP\Files\ObjectStore\IObjectStore;
3031
use OCP\Files\StorageAuthException;
3132
use OCP\Files\StorageNotAvailableException;
3233
use OpenCloud\Common\Service\Catalog;
3334
use OpenCloud\Common\Service\CatalogItem;
3435
use OpenCloud\Identity\Resource\Token;
36+
use OpenCloud\ObjectStore\Exception\ObjectNotFoundException;
3537
use OpenCloud\ObjectStore\Service;
3638
use OpenCloud\OpenStack;
3739
use OpenCloud\Rackspace;
@@ -251,13 +253,17 @@ public function writeObject($urn, $stream) {
251253
* @throws Exception from openstack lib when something goes wrong
252254
*/
253255
public function readObject($urn) {
254-
$this->init();
255-
$object = $this->container->getObject($urn);
256-
257-
// we need to keep a reference to objectContent or
258-
// the stream will be closed before we can do anything with it
259-
/** @var $objectContent \Guzzle\Http\EntityBody * */
260-
$objectContent = $object->getContent();
256+
try {
257+
$this->init();
258+
$object = $this->container->getObject($urn);
259+
260+
// we need to keep a reference to objectContent or
261+
// the stream will be closed before we can do anything with it
262+
/** @var $objectContent \Guzzle\Http\EntityBody * */
263+
$objectContent = $object->getContent();
264+
} catch (ObjectNotFoundException $e) {
265+
throw new NotFoundException("object $urn not found in object store");
266+
}
261267
$objectContent->rewind();
262268

263269
$stream = $objectContent->getStream();

0 commit comments

Comments
 (0)