Skip to content

Commit 89350ae

Browse files
committed
fix: Use new getOrCreate method and fix code issues
Signed-off-by: Côme Chilliet <[email protected]>
1 parent 77f9fe1 commit 89350ae

File tree

3 files changed

+15
-40
lines changed

3 files changed

+15
-40
lines changed

lib/private/Files/Node/LazyUserFolder.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use OCP\IConfig;
2020
use OCP\IUser;
2121
use OCP\Server;
22-
use Psr\Log\LoggerInterface;
2322

2423
class LazyUserFolder extends LazyFolder implements IUserFolder {
2524
private string $path;
@@ -48,19 +47,8 @@ public function __construct(
4847
$rootFolder,
4948
function () use ($user): UserFolder {
5049
$root = $this->getRootFolder();
51-
if (!$root->nodeExists('/' . $user->getUID())) {
52-
$parent = $root->newFolder('/' . $user->getUID());
53-
} else {
54-
$parent = $root->get('/' . $user->getUID());
55-
}
56-
if (!($parent instanceof Folder)) {
57-
$e = new \RuntimeException();
58-
\OCP\Server::get(LoggerInterface::class)->error('User root storage is not a folder: ' . $this->path, [
59-
'exception' => $e,
60-
]);
61-
throw $e;
62-
}
63-
$realFolder = $root->newFolder('/' . $user->getUID() . '/files');
50+
$parent = $root->getOrCreateFolder('/' . $user->getUID(), maxRetries: 1);
51+
$realFolder = $root->getOrCreateFolder('/' . $user->getUID() . '/files', maxRetries: 1);
6452
return new UserFolder(
6553
$root,
6654
new View($parent->getPath()),

lib/private/Files/Node/Root.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -346,31 +346,17 @@ public function getUserFolder($userId) {
346346

347347
if (!$this->userFolderCache->hasKey($userId)) {
348348
if ($this->mountManager->getSetupManager()->isSetupComplete($userObject)) {
349-
try {
350-
$folder = $this->get('/' . $userId . '/files');
351-
if (!$folder instanceof \OCP\Files\Folder) {
352-
throw new \Exception("Account folder for \"$userId\" exists as a file");
353-
}
354-
} catch (NotFoundException $e) {
355-
if (!$this->nodeExists('/' . $userId)) {
356-
$parent = $this->newFolder('/' . $userId);
357-
} else {
358-
$parent = $this->get('/' . $userId);
359-
if (!$parent instanceof \OCP\Files\Folder) {
360-
throw new \Exception("Account folder for \"$userId\" exists as a file");
361-
}
362-
}
363-
$realFolder = $this->newFolder('/' . $userId . '/files');
364-
$folder = new UserFolder(
365-
$this->root,
366-
$this->view,
367-
$realFolder->getPath(),
368-
$parent,
369-
Server::get(IConfig::class),
370-
$userObject,
371-
$this->cacheFactory,
372-
);
373-
}
349+
$parent = $this->getOrCreateFolder('/' . $userId, maxRetries: 1);
350+
$realFolder = $this->getOrCreateFolder('/' . $userId . '/files', maxRetries: 1);
351+
$folder = new UserFolder(
352+
$this,
353+
$this->view,
354+
$realFolder->getPath(),
355+
$parent,
356+
Server::get(IConfig::class),
357+
$userObject,
358+
$this->cacheFactory,
359+
);
374360
} else {
375361
$folder = new LazyUserFolder($this, $userObject, $this->mountManager, $this->useDefaultHomeFoldersPermissions);
376362
}

lib/private/Files/Node/UserFolder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use OC\Files\Storage\Wrapper\Quota;
1111
use OC\Files\View;
12+
use OCP\Files\Folder as IFolder;
1213
use OCP\Files\IRootFolder;
1314
use OCP\Files\IUserFolder;
1415
use OCP\ICacheFactory;
@@ -24,7 +25,7 @@ public function __construct(
2425
IRootFolder $root,
2526
View $view,
2627
string $path,
27-
Folder $parent,
28+
IFolder $parent,
2829
protected IConfig $config,
2930
protected IUser $user,
3031
protected ICacheFactory $cacheFactory,

0 commit comments

Comments
 (0)