Skip to content
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

Make it easier to debug issue #32304 #32961

Merged
merged 2 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/private/Files/Node/LazyFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OC\Files\Node;

use OC\Files\Utils\PathHelper;
use OCP\Files\Folder;
use OCP\Constants;

/**
Expand All @@ -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 */
Expand All @@ -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;
Expand Down
17 changes: 14 additions & 3 deletions lib/private/Files/Node/LazyUserFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down