Skip to content

Commit 9c19541

Browse files
committed
handle cases where SharedStorage::init isn't initializing the storage
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent ca747b9 commit 9c19541

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

apps/files_sharing/lib/SharedStorage.php

+27-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,17 @@
5555
use OCP\IUserManager;
5656
use OCP\Lock\ILockingProvider;
5757
use OCP\Share\IShare;
58+
use Psr\Log\LoggerInterface;
5859

5960
/**
6061
* Convert target path to source path and pass the function call to the correct storage provider
6162
*/
6263
class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage, IDisableEncryptionStorage {
64+
/**
65+
* @psalm-suppress NonInvariantDocblockPropertyType
66+
* @var \OC\Files\Storage\Storage|null $storage
67+
*/
68+
protected $storage;
6369

6470
/** @var \OCP\Share\IShare */
6571
private $superShare;
@@ -200,7 +206,17 @@ public function instanceOfStorage($class): bool {
200206
])) {
201207
return false;
202208
}
203-
return parent::instanceOfStorage($class);
209+
if (ltrim($class, '\\') === 'OC\Files\Storage\Shared') {
210+
// FIXME Temporary fix to keep existing checks working
211+
return true;
212+
}
213+
if (is_a($this, $class)) {
214+
return true;
215+
}
216+
217+
$storage = $this->getWrapperStorage();
218+
219+
return $storage->instanceOfStorage($class);
204220
}
205221

206222
/**
@@ -532,6 +548,16 @@ public function getSourceStorage() {
532548

533549
public function getWrapperStorage() {
534550
$this->init();
551+
552+
// `init` should handle this, but apparently it sometimes doesn't
553+
if (!$this->storage instanceof IStorage) {
554+
$e = new \Exception('Share source storage is null after initializing for share: ' . $this->getShare()->getId());
555+
$this->storage = new FailedStorage(['exception' => $e]);
556+
$this->cache = new FailedCache();
557+
$this->rootPath = '';
558+
$this->logger->logException($e);
559+
}
560+
535561
return $this->storage;
536562
}
537563

0 commit comments

Comments
 (0)