Skip to content

Commit bfda90d

Browse files
authored
Merge pull request #17927 from nextcloud/backport/17924/stable16
[stable16] Check quota before transfer ownership
2 parents 4ef8ff5 + 5c94ae2 commit bfda90d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

apps/files/lib/Command/TransferOwnership.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OC\Files\View;
3333
use OCP\Files\FileInfo;
3434
use OCP\Files\IHomeStorage;
35+
use OCP\Files\IRootFolder;
3536
use OCP\Files\Mount\IMountManager;
3637
use OCP\IUser;
3738
use OCP\IUserManager;
@@ -76,7 +77,10 @@ class TransferOwnership extends Command {
7677
/** @var string */
7778
private $finalTarget;
7879

79-
public function __construct(IUserManager $userManager, IManager $shareManager, IMountManager $mountManager) {
80+
public function __construct(IUserManager $userManager,
81+
IManager $shareManager,
82+
IMountManager $mountManager,
83+
IRootFolder $rootFolder) {
8084
$this->userManager = $userManager;
8185
$this->shareManager = $shareManager;
8286
$this->mountManager = $mountManager;
@@ -174,6 +178,15 @@ private function walkFiles(View $view, $path, \Closure $callBack) {
174178
*/
175179
protected function analyse(OutputInterface $output) {
176180
$view = new View();
181+
182+
$output->writeln('Validating quota');
183+
$size = $view->getFileInfo($this->sourcePath, false)->getSize(false);
184+
$freeSpace = $view->free_space($this->destinationUser . '/files/');
185+
if ($size > $freeSpace) {
186+
$output->writeln('<error>Target user does not have enough free space available</error>');
187+
throw new \Exception('Execution terminated');
188+
}
189+
177190
$output->writeln("Analysing files of $this->sourceUser ...");
178191
$progress = new ProgressBar($output);
179192
$progress->start();
@@ -207,7 +220,6 @@ function (FileInfo $fileInfo) use ($progress, $self) {
207220
}
208221
throw new \Exception('Execution terminated.');
209222
}
210-
211223
}
212224

213225
/**

0 commit comments

Comments
 (0)