-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
handle cases where SharedStorage::init isn't initializing the storage #33985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,11 +55,17 @@ | |
| 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 { | ||
| /** | ||
| * @psalm-suppress NonInvariantDocblockPropertyType | ||
| * @var \OC\Files\Storage\Storage|null $storage | ||
| */ | ||
| protected $storage; | ||
|
|
||
| /** @var \OCP\Share\IShare */ | ||
| private $superShare; | ||
|
|
@@ -82,10 +88,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto | |
| /** @var string */ | ||
| private $user; | ||
|
|
||
| /** | ||
| * @var \OCP\ILogger | ||
| */ | ||
| private $logger; | ||
| private LoggerInterface $logger; | ||
|
|
||
| /** @var IStorage */ | ||
| private $nonMaskedStorage; | ||
|
|
@@ -102,7 +105,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto | |
|
|
||
| public function __construct($arguments) { | ||
| $this->ownerView = $arguments['ownerView']; | ||
| $this->logger = \OC::$server->getLogger(); | ||
| $this->logger = \OC::$server->get(LoggerInterface::class); | ||
|
|
||
| $this->superShare = $arguments['superShare']; | ||
| $this->groupedShares = $arguments['groupedShares']; | ||
|
|
@@ -164,18 +167,21 @@ private function init() { | |
| } catch (NotFoundException $e) { | ||
| // original file not accessible or deleted, set FailedStorage | ||
| $this->storage = new FailedStorage(['exception' => $e]); | ||
| $this->nonMaskedStorage = $this->storage; | ||
| $this->cache = new FailedCache(); | ||
| $this->rootPath = ''; | ||
| } catch (NoUserException $e) { | ||
| // sharer user deleted, set FailedStorage | ||
| $this->storage = new FailedStorage(['exception' => $e]); | ||
| $this->nonMaskedStorage = $this->storage; | ||
| $this->cache = new FailedCache(); | ||
| $this->rootPath = ''; | ||
| } catch (\Exception $e) { | ||
| $this->storage = new FailedStorage(['exception' => $e]); | ||
| $this->nonMaskedStorage = $this->storage; | ||
| $this->cache = new FailedCache(); | ||
| $this->rootPath = ''; | ||
| $this->logger->logException($e); | ||
| $this->logger->error($e->getMessage(), ['exception' => $e]); | ||
| } | ||
|
|
||
| if (!$this->nonMaskedStorage) { | ||
|
|
@@ -200,7 +206,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 | ||
| return true; | ||
| } | ||
| if (is_a($this, $class)) { | ||
| return true; | ||
| } | ||
|
|
||
| $storage = $this->getWrapperStorage(); | ||
|
|
||
| return $storage->instanceOfStorage($class); | ||
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -532,6 +548,17 @@ public function getSourceStorage() { | |
|
|
||
| public function getWrapperStorage() { | ||
| $this->init(); | ||
|
|
||
| // `init` should handle this, but apparently it sometimes doesn't | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the reason for why it doesn't known? |
||
| 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->nonMaskedStorage = $this->storage; | ||
| $this->cache = new FailedCache(); | ||
| $this->rootPath = ''; | ||
| $this->logger->error($e->getMessage(), ['exception' => $e]); | ||
| } | ||
|
|
||
| return $this->storage; | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.