99namespace OCA \Files_Trashbin \Sabre ;
1010
1111use OC \Files \FileInfo ;
12- use OC \Files \View ;
1312use OCA \DAV \Connector \Sabre \FilesPlugin ;
1413use OCA \Files_Trashbin \Trash \ITrashItem ;
14+ use OCP \Files \IRootFolder ;
15+ use OCP \Files \Mount \IMountManager ;
1516use OCP \IPreview ;
1617use Psr \Log \LoggerInterface ;
1718use 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