Skip to content

Commit d54f595

Browse files
committed
Make it easier to debug issue #32304
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent dbc2c23 commit d54f595

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/private/Files/Node/LazyFolder.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace OC\Files\Node;
2828

2929
use OC\Files\Utils\PathHelper;
30+
use OCP\Files\Folder;
3031
use OCP\Constants;
3132

3233
/**
@@ -37,8 +38,8 @@
3738
*
3839
* @package OC\Files\Node
3940
*/
40-
class LazyFolder implements \OCP\Files\Folder {
41-
/** @var \Closure */
41+
class LazyFolder implements Folder {
42+
/** @var \Closure(): Folder */
4243
private $folderClosure;
4344

4445
/** @var LazyFolder | null */
@@ -49,7 +50,7 @@ class LazyFolder implements \OCP\Files\Folder {
4950
/**
5051
* LazyFolder constructor.
5152
*
52-
* @param \Closure $folderClosure
53+
* @param \Closure(): Folder $folderClosure
5354
*/
5455
public function __construct(\Closure $folderClosure, array $data = []) {
5556
$this->folderClosure = $folderClosure;

lib/private/Files/Node/LazyUserFolder.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
use OCP\Constants;
2828
use OCP\Files\IRootFolder;
2929
use OCP\Files\NotFoundException;
30+
use OCP\Files\Folder;
31+
use OCP\Files\File;
3032
use OCP\IUser;
33+
use Psr\Log\LoggerInterface;
3134

3235
class LazyUserFolder extends LazyFolder {
3336
private IRootFolder $root;
@@ -38,14 +41,22 @@ public function __construct(IRootFolder $rootFolder, IUser $user) {
3841
$this->root = $rootFolder;
3942
$this->user = $user;
4043
$this->path = '/' . $user->getUID() . '/files';
41-
parent::__construct(function () use ($user) {
44+
parent::__construct(function () use ($user): Folder {
4245
try {
43-
return $this->root->get('/' . $user->getUID() . '/files');
46+
$node = $this->root->get($this->path);
47+
if ($node instanceof File) {
48+
$e = new \RuntimeException();
49+
\OCP\Server::get(LoggerInterface::class)->error('User root storage is not a folder: ' . $this->path, [
50+
'exception' => $e,
51+
]);
52+
throw $e;
53+
}
54+
return $node;
4455
} catch (NotFoundException $e) {
4556
if (!$this->root->nodeExists('/' . $user->getUID())) {
4657
$this->root->newFolder('/' . $user->getUID());
4758
}
48-
return $this->root->newFolder('/' . $user->getUID() . '/files');
59+
return $this->root->newFolder($this->path);
4960
}
5061
}, [
5162
'path' => $this->path,
@@ -56,7 +67,7 @@ public function __construct(IRootFolder $rootFolder, IUser $user) {
5667
}
5768

5869
public function get($path) {
59-
return $this->root->get('/' . $this->user->getUID() . '/files/' . ltrim($path, '/'));
70+
return $this->root->get($this->path . ltrim($path, '/'));
6071
}
6172

6273
/**

0 commit comments

Comments
 (0)