Skip to content

Commit 5309b03

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 91a7e65 commit 5309b03

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

apps/files_trashbin/lib/Sabre/TrashbinPlugin.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use OC\Files\View;
1414
use OCA\DAV\Connector\Sabre\FilesPlugin;
1515
use OCA\Files_Trashbin\Trash\ITrashItem;
16+
use OCP\Files\IRootFolder;
17+
use OCP\Files\Mount\IMountManager;
1618
use OCP\IPreview;
1719
use Psr\Log\LoggerInterface;
1820
use Sabre\DAV\INode;
@@ -44,6 +46,8 @@ class TrashbinPlugin extends ServerPlugin {
4446
public function __construct(
4547
private readonly IPreview $previewManager,
4648
private readonly View $view,
49+
private readonly IRootFolder $rootFolder,
50+
private readonly IMountManager $mountManager,
4751
) {
4852
}
4953

@@ -175,7 +179,16 @@ public function beforeMove(string $sourcePath, string $destinationPath): bool {
175179
return true;
176180
}
177181

178-
$freeSpace = $this->view->free_space($destinationParentPath);
182+
$userFolder = $this->rootFolder->getUserFolder($fileInfo->getUser()->getUID());
183+
$originalPath = $userFolder->getFullPath(dirname($fileInfo->getOriginalLocation()));
184+
185+
// Since the parent folder might no longer exist, we don't try to get the parent node to check the free space
186+
// instead we resolve the mount where the restore would go to, and check that for the free space
187+
$originalMount = $this->mountManager->find($originalPath);
188+
if (!$originalMount) {
189+
throw new \Exception('no mount found when looking for restore path');
190+
}
191+
$freeSpace = $originalMount->getStorage()->free_space($originalMount->getInternalPath($originalPath));
179192

180193
if (
181194
$freeSpace === FileInfo::SPACE_NOT_COMPUTED

0 commit comments

Comments
 (0)