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 committed Apr 30, 2024
1 parent 06b83d6 commit e91aae1
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 <[email protected]>
*
* @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 {

Check failure on line 33 in lib/Mount/GroupFolderEncryptionJail.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UnimplementedInterfaceMethod

lib/Mount/GroupFolderEncryptionJail.php:33:7: UnimplementedInterfaceMethod: Method setowner is not defined on class OCA\GroupFolders\Mount\GroupFolderEncryptionJail (see https://psalm.dev/044)
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);

Check failure on line 42 in lib/Mount/GroupFolderEncryptionJail.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/Mount/GroupFolderEncryptionJail.php:42:14: UndefinedClass: Class, interface or enum named OC\Files\Cache\Wrapper\CacheJail does not exist (see https://psalm.dev/019)

Check failure on line 42 in lib/Mount/GroupFolderEncryptionJail.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Mount/GroupFolderEncryptionJail.php:42:38: UndefinedThisPropertyFetch: Instance property OCA\GroupFolders\Mount\GroupFolderEncryptionJail::$rootPath is not defined (see https://psalm.dev/041)
}
}
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 e91aae1

Please sign in to comment.