From 85770f3b9f12ef2ab054fca2327c2b6497abf2ca Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 21 Jun 2022 16:10:48 +0200 Subject: [PATCH 1/2] Make it easier to debug issue #32304 Signed-off-by: Carl Schwan --- lib/private/Files/Node/LazyFolder.php | 7 ++++--- lib/private/Files/Node/LazyUserFolder.php | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php index cc1f64889a153..c843baabade00 100644 --- a/lib/private/Files/Node/LazyFolder.php +++ b/lib/private/Files/Node/LazyFolder.php @@ -27,6 +27,7 @@ namespace OC\Files\Node; use OC\Files\Utils\PathHelper; +use OCP\Files\Folder; use OCP\Constants; /** @@ -37,8 +38,8 @@ * * @package OC\Files\Node */ -class LazyFolder implements \OCP\Files\Folder { - /** @var \Closure */ +class LazyFolder implements Folder { + /** @var \Closure(): Folder */ private $folderClosure; /** @var LazyFolder | null */ @@ -49,7 +50,7 @@ class LazyFolder implements \OCP\Files\Folder { /** * LazyFolder constructor. * - * @param \Closure $folderClosure + * @param \Closure(): Folder $folderClosure */ public function __construct(\Closure $folderClosure, array $data = []) { $this->folderClosure = $folderClosure; diff --git a/lib/private/Files/Node/LazyUserFolder.php b/lib/private/Files/Node/LazyUserFolder.php index 81009532dbfd3..e9a15555c42f4 100644 --- a/lib/private/Files/Node/LazyUserFolder.php +++ b/lib/private/Files/Node/LazyUserFolder.php @@ -28,7 +28,10 @@ use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountManager; use OCP\Files\NotFoundException; +use OCP\Files\Folder; +use OCP\Files\File; use OCP\IUser; +use Psr\Log\LoggerInterface; class LazyUserFolder extends LazyFolder { private IRootFolder $root; @@ -41,14 +44,22 @@ public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager $this->user = $user; $this->mountManager = $mountManager; $this->path = '/' . $user->getUID() . '/files'; - parent::__construct(function () use ($user) { + parent::__construct(function () use ($user): Folder { try { - return $this->root->get('/' . $user->getUID() . '/files'); + $node = $this->root->get($this->path); + if ($node instanceof File) { + $e = new \RuntimeException(); + \OCP\Server::get(LoggerInterface::class)->error('User root storage is not a folder: ' . $this->path, [ + 'exception' => $e, + ]); + throw $e; + } + return $node; } catch (NotFoundException $e) { if (!$this->root->nodeExists('/' . $user->getUID())) { $this->root->newFolder('/' . $user->getUID()); } - return $this->root->newFolder('/' . $user->getUID() . '/files'); + return $this->root->newFolder($this->path); } }, [ 'path' => $this->path, @@ -59,7 +70,7 @@ public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager } public function get($path) { - return $this->root->get('/' . $this->user->getUID() . '/files/' . ltrim($path, '/')); + return $this->root->get('/' . $this->user->getUID() . '/files' . ltrim($path, '/')); } /** From 1cc1866ba3ce27742e75abb4dc74a48df352f6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <91878298+come-nc@users.noreply.github.com> Date: Tue, 9 May 2023 10:59:31 +0200 Subject: [PATCH 2/2] Add back missing slash in LazyUserFolder path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> --- lib/private/Files/Node/LazyUserFolder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Files/Node/LazyUserFolder.php b/lib/private/Files/Node/LazyUserFolder.php index e9a15555c42f4..8fbdec4b49d07 100644 --- a/lib/private/Files/Node/LazyUserFolder.php +++ b/lib/private/Files/Node/LazyUserFolder.php @@ -70,7 +70,7 @@ public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager } public function get($path) { - return $this->root->get('/' . $this->user->getUID() . '/files' . ltrim($path, '/')); + return $this->root->get('/' . $this->user->getUID() . '/files/' . ltrim($path, '/')); } /**