Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] feat(transfer-ownership): Correctly react to encrypted files #47781

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions apps/files/lib/Service/OwnershipTransferService.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,41 +204,64 @@ private function walkFiles(View $view, $path, Closure $callBack) {
/**
* @param OutputInterface $output
*
* @throws \Exception
* @throws TransferOwnershipException
*/
protected function analyse(string $sourceUid,
string $destinationUid,
string $sourcePath,
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('');

Expand All @@ -249,7 +272,7 @@ function (FileInfo $fileInfo) use ($progress, &$encryptedFiles) {
/** @var FileInfo $encryptedFile */
$output->writeln(" " . $encryptedFile->getPath());
}
throw new \Exception('Execution terminated.');
throw new TransferOwnershipException('Some files are encrypted - please decrypt them first.', 1);
}
}

Expand Down
Loading