diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2024-09-05 21:36:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-05 21:36:15 +0200 |
commit | 257a9dad5b9fc2cf7db0fd9a47050c18629ab601 (patch) | |
tree | 6a6b6d66d38173c6bba3e8d0a718900b23cc651e | |
parent | 86901b3ccecb939bf8bd315ae98112688c86cb9a (diff) | |
parent | 817b8c076dba50a62cc014ce460ce112f8223e26 (diff) | |
download | nextcloud-server-257a9dad5b9fc2cf7db0fd9a47050c18629ab601.tar.gz nextcloud-server-257a9dad5b9fc2cf7db0fd9a47050c18629ab601.zip |
Merge pull request #47779 from nextcloud/backport/47519/stable28
[stable28] feat(transfer-ownership): Correctly react to encrypted files
-rw-r--r-- | apps/files/lib/Service/OwnershipTransferService.php | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php index 4c0d468516a..0b25b8f4e28 100644 --- a/apps/files/lib/Service/OwnershipTransferService.php +++ b/apps/files/lib/Service/OwnershipTransferService.php @@ -223,7 +223,7 @@ class OwnershipTransferService { /** * @param OutputInterface $output * - * @throws \Exception + * @throws TransferOwnershipException */ protected function analyse(string $sourceUid, string $destinationUid, @@ -231,33 +231,56 @@ class OwnershipTransferService { View $view, OutputInterface $output): void { $output->writeln('Validating quota'); - $size = $view->getFileInfo($sourcePath, false)->getSize(false); + $sourceFileInfo = $view->getFileInfo($sourcePath, false); + if ($sourceFileInfo === false) { + throw new TransferOwnershipException("Unknown path provided: $sourcePath", 1); + } + $size = $sourceFileInfo->getSize(false); $freeSpace = $view->free_space($destinationUid . '/files/'); if ($size > $freeSpace && $freeSpace !== FileInfo::SPACE_UNKNOWN) { - $output->writeln('<error>Target user does not have enough free space available.</error>'); - throw new \Exception('Execution terminated.'); + throw new TransferOwnershipException('Target user does not have enough free space available.', 1); } $output->writeln("Analysing files of $sourceUid ..."); $progress = new ProgressBar($output); $progress->start(); + if ($this->encryptionManager->isEnabled()) { + $masterKeyEnabled = \OCP\Server::get(\OCA\Encryption\Util::class)->isMasterKeyEnabled(); + } else { + $masterKeyEnabled = false; + } $encryptedFiles = []; - $this->walkFiles($view, $sourcePath, - function (FileInfo $fileInfo) use ($progress, &$encryptedFiles) { - if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) { - // only analyze into folders from main storage, - if (!$fileInfo->getStorage()->instanceOfStorage(IHomeStorage::class)) { - return false; - } - return true; - } - $progress->advance(); - if ($fileInfo->isEncrypted()) { - $encryptedFiles[] = $fileInfo; - } - return true; - }); + if ($sourceFileInfo->getType() === FileInfo::TYPE_FOLDER) { + if ($sourceFileInfo->isEncrypted()) { + /* Encrypted folder means e2ee encrypted */ + $encryptedFiles[] = $sourceFileInfo; + } else { + $this->walkFiles($view, $sourcePath, + function (FileInfo $fileInfo) use ($progress, $masterKeyEnabled, &$encryptedFiles) { + if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) { + // only analyze into folders from main storage, + if (!$fileInfo->getStorage()->instanceOfStorage(IHomeStorage::class)) { + return false; + } + if ($fileInfo->isEncrypted()) { + /* Encrypted folder means e2ee encrypted, we cannot transfer it */ + $encryptedFiles[] = $fileInfo; + } + return true; + } + $progress->advance(); + if ($fileInfo->isEncrypted() && !$masterKeyEnabled) { + /* Encrypted file means SSE, we can only transfer it if master key is enabled */ + $encryptedFiles[] = $fileInfo; + } + return true; + }); + } + } elseif ($sourceFileInfo->isEncrypted() && !$masterKeyEnabled) { + /* Encrypted file means SSE, we can only transfer it if master key is enabled */ + $encryptedFiles[] = $sourceFileInfo; + } $progress->finish(); $output->writeln(''); @@ -268,7 +291,7 @@ class OwnershipTransferService { /** @var FileInfo $encryptedFile */ $output->writeln(" " . $encryptedFile->getPath()); } - throw new \Exception('Execution terminated.'); + throw new TransferOwnershipException('Some files are encrypted - please decrypt them first.', 1); } } |