Skip to content

Commit 0be9e89

Browse files
committed
fix: check free space in the proper folder when restoring from trash
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent b2eb302 commit 0be9e89

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

apps/files_trashbin/lib/Sabre/TrashbinPlugin.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
namespace OCA\Files_Trashbin\Sabre;
1010

1111
use OC\Files\FileInfo;
12-
use OC\Files\View;
1312
use OCA\DAV\Connector\Sabre\FilesPlugin;
1413
use OCA\Files_Trashbin\Trash\ITrashItem;
14+
use OCP\Files\IRootFolder;
15+
use OCP\Files\Mount\IMountManager;
1516
use OCP\IPreview;
1617
use Psr\Log\LoggerInterface;
1718
use Sabre\DAV\INode;
@@ -36,7 +37,8 @@ class TrashbinPlugin extends ServerPlugin {
3637

3738
public function __construct(
3839
private IPreview $previewManager,
39-
private View $view,
40+
private IRootFolder $rootFolder,
41+
private IMountManager $mountManager,
4042
) {
4143
}
4244

@@ -164,9 +166,20 @@ public function beforeMove(string $sourcePath, string $destinationPath): bool {
164166
if (!$fileInfo instanceof ITrashItem) {
165167
return true;
166168
}
167-
$restoreFolder = dirname($fileInfo->getOriginalLocation());
168-
$freeSpace = $this->view->free_space($restoreFolder);
169-
if ($freeSpace === FileInfo::SPACE_NOT_COMPUTED ||
169+
170+
$userFolder = $this->rootFolder->getUserFolder($fileInfo->getUser()->getUID());
171+
$originalPath = $userFolder->getFullPath(dirname($fileInfo->getOriginalLocation()));
172+
173+
// Since the parent folder might no longer exist, we don't try to get the parent node to check the free space
174+
// instead we resolve the mount where the restore would go to, and check that for the free space
175+
$originalMount = $this->mountManager->find($originalPath);
176+
if (!$originalMount) {
177+
throw new \Exception('no mount found when looking for restore path');
178+
}
179+
$freeSpace = $originalMount->getStorage()->free_space($originalMount->getInternalPath($originalPath));
180+
181+
if (
182+
$freeSpace === FileInfo::SPACE_NOT_COMPUTED ||
170183
$freeSpace === FileInfo::SPACE_UNKNOWN ||
171184
$freeSpace === FileInfo::SPACE_UNLIMITED) {
172185
return true;

0 commit comments

Comments
 (0)