Skip to content

Commit 3525192

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

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

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;
@@ -592,6 +593,9 @@ private function convertToSabreException(\Exception $e) {
592593
if ($e instanceof StorageNotAvailableException) {
593594
throw new ServiceUnavailable('Failed to write file contents: ' . $e->getMessage(), 0, $e);
594595
}
596+
if ($e instanceof NotFoundException) {
597+
throw new NotFound('File not found: ' . $e->getMessage(), 0, $e);
598+
}
595599

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

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Icewind\Streams\IteratorDirectory;
3030
use OC\Files\Cache\CacheEntry;
3131
use OC\Files\Stream\CountReadStream;
32+
use OCP\Files\NotFoundException;
3233
use OCP\Files\ObjectStore\IObjectStore;
3334

3435
class ObjectStoreStorage extends \OC\Files\Storage\Common {
@@ -275,10 +276,16 @@ public function fopen($path, $mode) {
275276
if (is_array($stat)) {
276277
try {
277278
return $this->objectStore->readObject($this->getURN($stat['fileid']));
279+
} catch (NotFoundException $e) {
280+
$this->logger->logException($e, [
281+
'app' => 'objectstore',
282+
'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
283+
]);
284+
throw $e;
278285
} catch (\Exception $ex) {
279286
$this->logger->logException($ex, [
280287
'app' => 'objectstore',
281-
'message' => 'Count not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
288+
'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
282289
]);
283290
return false;
284291
}

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)