Skip to content

Commit c0ff84c

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

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

apps/dav/lib/Upload/RootCollection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727
namespace OCA\DAV\Upload;
2828

29+
use OCP\Files\IRootFolder;
30+
use OCP\IUserSession;
2931
use Sabre\DAVACL\AbstractPrincipalCollection;
3032
use Sabre\DAVACL\PrincipalBackend;
3133

@@ -45,7 +47,7 @@ public function __construct(PrincipalBackend\BackendInterface $principalBackend,
4547
* @inheritdoc
4648
*/
4749
public function getChildForPrincipal(array $principalInfo): UploadHome {
48-
return new UploadHome($principalInfo, $this->cleanupService);
50+
return new UploadHome($principalInfo, $this->cleanupService, $this->rootFolder, $this->userSession);
4951
}
5052

5153
/**

apps/dav/lib/Upload/UploadHome.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626
namespace OCA\DAV\Upload;
2727

28-
use OC\Files\Filesystem;
2928
use OC\Files\View;
3029
use OCA\DAV\Connector\Sabre\Directory;
3130
use Sabre\DAV\Exception\Forbidden;
@@ -84,13 +83,24 @@ public function getLastModified() {
8483
return $this->impl()->getLastModified();
8584
}
8685

87-
/**
88-
* @return Directory
89-
*/
90-
private function impl() {
91-
$view = $this->getView();
92-
$rootInfo = $view->getFileInfo('');
93-
return new Directory($view, $rootInfo);
86+
private function getUploadFolder(): Folder {
87+
if ($this->uploadFolder === null) {
88+
$user = $this->userSession->getUser();
89+
if (!$user) {
90+
throw new Forbidden('Not logged in');
91+
}
92+
$path = '/' . $user->getUID() . '/uploads';
93+
try {
94+
$folder = $this->rootFolder->get($path);
95+
if (!$folder instanceof Folder) {
96+
throw new \Exception('Upload folder is a file');
97+
}
98+
$this->uploadFolder = $folder;
99+
} catch (NotFoundException $e) {
100+
$this->uploadFolder = $this->rootFolder->newFolder($path);
101+
}
102+
}
103+
return $this->uploadFolder;
94104
}
95105

96106
private function getView() {
@@ -104,8 +114,6 @@ private function getView() {
104114
}
105115

106116
private function getStorage() {
107-
$view = $this->getView();
108-
$storage = $view->getFileInfo('')->getStorage();
109-
return $storage;
117+
return $this->getUploadFolder()->getStorage();
110118
}
111119
}

0 commit comments

Comments
 (0)