Skip to content

Commit 82f99c9

Browse files
icewind1991backportbot[bot]
authored andcommitted
fix: rework UploadFolder implementation
Signed-off-by: Robin Appelman <robin@icewind.nl> [skip ci]
1 parent 3b49ee1 commit 82f99c9

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

apps/dav/lib/Upload/RootCollection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace OCA\DAV\Upload;
1111

12+
use OCP\Files\IRootFolder;
13+
use OCP\IUserSession;
1214
use Sabre\DAVACL\AbstractPrincipalCollection;
1315
use Sabre\DAVACL\PrincipalBackend;
1416

@@ -18,6 +20,8 @@ public function __construct(
1820
PrincipalBackend\BackendInterface $principalBackend,
1921
string $principalPrefix,
2022
private CleanupService $cleanupService,
23+
private IRootFolder $rootFolder,
24+
private IUserSession $userSession,
2125
) {
2226
parent::__construct($principalBackend, $principalPrefix);
2327
}
@@ -26,7 +30,7 @@ public function __construct(
2630
* @inheritdoc
2731
*/
2832
public function getChildForPrincipal(array $principalInfo): UploadHome {
29-
return new UploadHome($principalInfo, $this->cleanupService);
33+
return new UploadHome($principalInfo, $this->cleanupService, $this->rootFolder, $this->userSession);
3034
}
3135

3236
/**

apps/dav/lib/Upload/UploadHome.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
*/
88
namespace OCA\DAV\Upload;
99

10-
use OC\Files\Filesystem;
1110
use OC\Files\View;
1211
use OCA\DAV\Connector\Sabre\Directory;
1312
use Sabre\DAV\Exception\Forbidden;
1413
use Sabre\DAV\ICollection;
1514

1615
class UploadHome implements ICollection {
16+
private ?Folder $uploadFolder = null;
17+
1718
public function __construct(
18-
private array $principalInfo,
19-
private CleanupService $cleanupService,
19+
private readonly array $principalInfo,
20+
private readonly CleanupService $cleanupService,
21+
private readonly IRootFolder $rootFolder,
22+
private readonly IUserSession $userSession,
2023
) {
2124
}
2225

@@ -62,13 +65,24 @@ public function getLastModified() {
6265
return $this->impl()->getLastModified();
6366
}
6467

65-
/**
66-
* @return Directory
67-
*/
68-
private function impl() {
69-
$view = $this->getView();
70-
$rootInfo = $view->getFileInfo('');
71-
return new Directory($view, $rootInfo);
68+
private function getUploadFolder(): Folder {
69+
if ($this->uploadFolder === null) {
70+
$user = $this->userSession->getUser();
71+
if (!$user) {
72+
throw new Forbidden('Not logged in');
73+
}
74+
$path = '/' . $user->getUID() . '/uploads';
75+
try {
76+
$folder = $this->rootFolder->get($path);
77+
if (!$folder instanceof Folder) {
78+
throw new \Exception('Upload folder is a file');
79+
}
80+
$this->uploadFolder = $folder;
81+
} catch (NotFoundException $e) {
82+
$this->uploadFolder = $this->rootFolder->newFolder($path);
83+
}
84+
}
85+
return $this->uploadFolder;
7286
}
7387

7488
private function getView() {
@@ -82,8 +96,6 @@ private function getView() {
8296
}
8397

8498
private function getStorage() {
85-
$view = $this->getView();
86-
$storage = $view->getFileInfo('')->getStorage();
87-
return $storage;
99+
return $this->getUploadFolder()->getStorage();
88100
}
89101
}

0 commit comments

Comments
 (0)