Skip to content

Commit c022a1a

Browse files
committed
fix(encryption): Ignore shared files in encrypt-all command
Copying and renaming a share will not encrypt it anyway. It will get encrypted when the owner’s files get encrypted. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 17e97e6 commit c022a1a

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

apps/encryption/lib/Crypto/EncryptAll.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCA\Encryption\KeyManager;
1313
use OCA\Encryption\Users\Setup;
1414
use OCA\Encryption\Util;
15+
use OCP\Files\FileInfo;
1516
use OCP\IConfig;
1617
use OCP\IL10N;
1718
use OCP\IUser;
@@ -247,14 +248,18 @@ protected function encryptUsersFiles($uid, ProgressBar $progress, $userCount) {
247248
$content = $this->rootView->getDirectoryContent($root);
248249
foreach ($content as $file) {
249250
$path = $root . '/' . $file['name'];
250-
if ($this->rootView->is_dir($path)) {
251+
if ($file->isShared()) {
252+
$progress->setMessage("Skip shared file/folder $path");
253+
$progress->advance();
254+
continue;
255+
} elseif ($file->getType() === FileInfo::TYPE_FOLDER) {
251256
$directories[] = $path;
252257
continue;
253258
} else {
254259
$progress->setMessage("encrypt files for user $userCount: $path");
255260
$progress->advance();
256261
try {
257-
if ($this->encryptFile($path) === false) {
262+
if ($this->encryptFile($file, $path) === false) {
258263
$progress->setMessage("encrypt files for user $userCount: $path (already encrypted)");
259264
$progress->advance();
260265
}
@@ -275,17 +280,9 @@ protected function encryptUsersFiles($uid, ProgressBar $progress, $userCount) {
275280
}
276281
}
277282

278-
/**
279-
* encrypt file
280-
*
281-
* @param string $path
282-
* @return bool
283-
*/
284-
protected function encryptFile($path) {
285-
283+
protected function encryptFile(FileInfo $fileInfo, string $path): bool {
286284
// skip already encrypted files
287-
$fileInfo = $this->rootView->getFileInfo($path);
288-
if ($fileInfo !== false && $fileInfo->isEncrypted()) {
285+
if ($fileInfo->isEncrypted()) {
289286
return true;
290287
}
291288

0 commit comments

Comments
 (0)