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 <danxuliu@gmail.com>
  • Loading branch information
danxuliu authored and icewind1991 committed Jul 26, 2024
1 parent 54e770e commit 3fdc5d3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
44 changes: 44 additions & 0 deletions lib/Mount/GroupFolderEncryptionJail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2024 Daniel CalviΓ±o SΓ‘nchez <danxuliu@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

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 @@ -232,11 +232,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 @@ -246,6 +246,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 3fdc5d3

Please sign in to comment.