Skip to content

Commit

Permalink
handle cases where SharedStorage::init isn't initializing the storage
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Sep 16, 2022
1 parent ca747b9 commit 25c7384
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;

/**
* Convert target path to source path and pass the function call to the correct storage provider
*/
class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage, IDisableEncryptionStorage {
/**
* @var \OC\Files\Storage\Storage|null $storage
*/
protected $storage;

/** @var \OCP\Share\IShare */
private $superShare;
Expand Down Expand Up @@ -200,7 +205,17 @@ public function instanceOfStorage($class): bool {
])) {
return false;
}
return parent::instanceOfStorage($class);
if (ltrim($class, '\\') === 'OC\Files\Storage\Shared') {
// FIXME Temporary fix to keep existing checks working
$class = '\OCA\Files_Sharing\SharedStorage';
}
if (is_a($this, $class)) {
return true;
}

$storage = $this->getWrapperStorage();

return $storage->instanceOfStorage($class);
}

/**
Expand Down Expand Up @@ -532,6 +547,16 @@ public function getSourceStorage() {

public function getWrapperStorage() {
$this->init();

// `init` should handle this, but apparently it sometimes doesn't
if (!$this->storage instanceof IStorage) {
$e = new \Exception('Share source storage is null after initializing for share: ' . $this->getShare()->getId());
$this->storage = new FailedStorage(['exception' => $e]);
$this->cache = new FailedCache();
$this->rootPath = '';
$this->logger->logException($e);
}

return $this->storage;
}

Expand Down

0 comments on commit 25c7384

Please sign in to comment.