Skip to content

Commit

Permalink
fix: Fix Encryption wrapper not seen by group folder cache
Browse files Browse the repository at this point in the history
Jail wrappers reuse the cache of the wrapped storage even if another
storage is explicitly given. Due to that, when the cache is got from an
storage and that storage has a Jail all the wrappers above it are not
known to the cache, and only those wrapped by the Jail are taken into
account.

In general that works fine, as in most cases the cache does not need to
know the details of a storage. However, it needs to know if an
Encryption wrapper is present in the storage when moving files into it,
as the file cache explicitly clears the "encrypted" flag when moving a
file from an encrypted storage to a non encrypted storage.

As the Encryption wrapper of groupfolders was not known to the cache all
files moved from an encrypted storage to an encrypted groupfolder ended
wrongly marked as not encrypted.

To solve that now the Jail used by groupfolders does not reuse the inner
cache when encryption is enabled, and instead passes the given storage.
This is applied only when encryption is enabled, as reusing the inner
cache was done as a performance optimization.

Signed-off-by: Daniel CalviΓ±o SΓ‘nchez <[email protected]>
  • Loading branch information
danxuliu authored and backportbot[bot] committed Aug 22, 2024
1 parent 040b2a2 commit f35cd76
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
29 changes: 29 additions & 0 deletions lib/Mount/GroupFolderEncryptionJail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\GroupFolders\Mount;

use OC\Files\Cache\Wrapper\CacheJail;
use OC\Files\Storage\Wrapper\Jail;

/**
* Jail with overridden behaviors specific to group folders when encryption is
* enabled.
*/
class GroupFolderEncryptionJail extends Jail {
public function getCache($path = '', $storage = null) {
if (!$storage) {
$storage = $this->getWrapperStorage();
}
// By default the Jail reuses the inner cache, but when encryption is
// enabled the storage needs to be passed to the cache so it takes into
// account the outer Encryption wrapper.
$sourceCache = $this->getWrapperStorage()->getCache($this->getUnjailedPath($path), $storage);
return new CacheJail($sourceCache, $this->rootPath);
}
}
12 changes: 8 additions & 4 deletions lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ public function getMount(
$cacheEntry['permissions'] &= $aclRootPermissions;
}

$baseStorage = new Jail([
'storage' => $storage,
'root' => $rootPath
]);
if ($this->enableEncryption) {
$baseStorage = new GroupFolderEncryptionJail([
'storage' => $storage,
'root' => $rootPath
]);
$quotaStorage = new GroupFolderStorage([
'storage' => $baseStorage,
'quota' => $quota,
Expand All @@ -244,6 +244,10 @@ public function getMount(
'mountOwner' => $user,
]);
} else {
$baseStorage = new Jail([
'storage' => $storage,
'root' => $rootPath
]);
$quotaStorage = new GroupFolderNoEncryptionStorage([
'storage' => $baseStorage,
'quota' => $quota,
Expand Down

0 comments on commit f35cd76

Please sign in to comment.