Skip to content

Commit a050ca5

Browse files
committed
forward object not found error in swift as dav 404
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent a79c7c7 commit a050ca5

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use OCP\Files\InvalidContentException;
5151
use OCP\Files\InvalidPathException;
5252
use OCP\Files\LockNotAcquiredException;
53+
use OCP\Files\NotFoundException;
5354
use OCP\Files\NotPermittedException;
5455
use OCP\Files\Storage;
5556
use OCP\Files\StorageNotAvailableException;
@@ -583,6 +584,9 @@ private function convertToSabreException(\Exception $e) {
583584
if ($e instanceof StorageNotAvailableException) {
584585
throw new ServiceUnavailable('Failed to write file contents: ' . $e->getMessage(), 0, $e);
585586
}
587+
if ($e instanceof NotFoundException) {
588+
throw new NotFound('File not found: ' . $e->getMessage(), 0, $e);
589+
}
586590

587591
throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e);
588592
}

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 8 additions & 0 deletions
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 {
@@ -274,6 +276,12 @@ public function fopen($path, $mode) {
274276
if (is_array($stat)) {
275277
try {
276278
return $this->objectStore->readObject($this->getURN($stat['fileid']));
279+
} catch (NotFoundException $e) {
280+
$this->logger->logException($e, [
281+
'app' => 'objectstore',
282+
'message' => 'Count not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
283+
]);
284+
throw $e;
277285
} catch (\Exception $ex) {
278286
$this->logger->logException($ex, [
279287
'app' => 'objectstore',

lib/private/Files/ObjectStore/Swift.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727

2828
use function GuzzleHttp\Psr7\stream_for;
2929
use Icewind\Streams\RetryWrapper;
30+
use OCP\Files\NotFoundException;
3031
use OCP\Files\ObjectStore\IObjectStore;
3132
use OCP\Files\StorageAuthException;
33+
use OpenStack\Common\Error\BadResponseError;
3234

3335
class Swift implements IObjectStore {
3436
/**
@@ -86,11 +88,19 @@ public function writeObject($urn, $stream) {
8688
* @throws \Exception from openstack lib when something goes wrong
8789
*/
8890
public function readObject($urn) {
89-
$object = $this->getContainer()->getObject($urn);
90-
91-
// we need to keep a reference to objectContent or
92-
// the stream will be closed before we can do anything with it
93-
$objectContent = $object->download();
91+
try {
92+
$object = $this->getContainer()->getObject($urn);
93+
94+
// we need to keep a reference to objectContent or
95+
// the stream will be closed before we can do anything with it
96+
$objectContent = $object->download();
97+
} catch (BadResponseError $e) {
98+
if ($e->getResponse()->getStatusCode() === 404) {
99+
throw new NotFoundException("object $urn not found in object store");
100+
} else {
101+
throw $e;
102+
}
103+
}
94104
$objectContent->rewind();
95105

96106
$stream = $objectContent->detach();

0 commit comments

Comments
 (0)