Skip to content

Commit

Permalink
Merge pull request #2836 from nextcloud/backport/2797/stable26
Browse files Browse the repository at this point in the history
[stable26] Revert: don't apply acls when scanning
  • Loading branch information
icewind1991 authored Feb 29, 2024
2 parents d9f026e + 3a78d61 commit a6c2362
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 28 deletions.
31 changes: 3 additions & 28 deletions lib/Mount/GroupFolderStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
use OC\Files\Cache\Scanner;
use OC\Files\ObjectStore\NoopScanner;
use OC\Files\ObjectStore\ObjectStoreStorage;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\Quota;
use OC\Files\Storage\Wrapper\Wrapper;
use OCA\GroupFolders\ACL\ACLStorageWrapper;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\IUser;
Expand Down Expand Up @@ -74,32 +71,10 @@ public function getCache($path = '', $storage = null) {
}

public function getScanner($path = '', $storage = null) {
// note that we explicitly don't used the passed in storage
// as we want to perform the scan on the underlying filesystem
// without any of the group folder permissions applied

/** @var Wrapper $storage */
$storage = $this->storage;

// we want to scan without ACLs applied
if ($storage->instanceOfStorage(ACLStorageWrapper::class)) {
// sanity check in case the code setting up the wrapper hierarchy is changed without updating this
if (!$this->storage instanceof Jail) {
throw new \Exception("groupfolder storage layout changed unexpectedly");
}

$jailRoot = $this->storage->getUnjailedPath('');
$aclStorage = $this->storage->getUnjailedStorage();

if (!$aclStorage instanceof ACLStorageWrapper) {
throw new \Exception("groupfolder storage layout changed unexpectedly");
}
$storage = new Jail([
'storage' => $aclStorage->getWrapperStorage(),
'root' => $jailRoot,
]);
/** @var \OC\Files\Storage\Wrapper\Wrapper $storage */
if (!$storage) {
$storage = $this;
}

if ($storage->instanceOfStorage(ObjectStoreStorage::class)) {
$storage->scanner = new NoopScanner($storage);
} elseif (!isset($storage->scanner)) {
Expand Down
60 changes: 60 additions & 0 deletions tests/ACL/ACLScannerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace OCA\groupfolders\tests\ACL;

use OC\Files\Storage\Temporary;
use OCA\GroupFolders\ACL\ACLManager;
use OCA\GroupFolders\ACL\ACLStorageWrapper;
use OCP\Constants;
use Test\TestCase;

/**
* @group DB
*/
class ACLScannerTest extends TestCase {
private function getAclManager(array $rules): ACLManager {
$manager = $this->getMockBuilder(ACLManager::class)
->disableOriginalConstructor()
->getMock();
$manager->method('getACLPermissionsForPath')
->willReturnCallback(function ($path) use ($rules) {
return $rules[$path] ?? Constants::PERMISSION_ALL;
});
return $manager;
}

public function testScanAclStorage() {
$baseStorage = new Temporary([]);
$baseStorage->mkdir('foo');
$baseStorage->mkdir('foo/bar');
$baseStorage->mkdir('foo/bar/asd');
$cache = $baseStorage->getCache();
$baseStorage->getScanner()->scan('');

$cache->update($cache->getId('foo/bar/asd'), ['size' => -1]);
$cache->calculateFolderSize('foo/bar');
$cache->calculateFolderSize('foo');

$this->assertEquals(-1, $cache->get('foo/bar')->getSize());

$acls = $this->getAclManager([
'foo/bar' => 0,
'foo/bar/asd' => 0,
]);

$aclStorage = new ACLStorageWrapper([
'storage' => $baseStorage,
'acl_manager' => $acls,
'in_share' => false,
]);

$scanner = $aclStorage->getScanner();
$aclCache = $aclStorage->getCache();
$scanner->scan('');

$this->assertEquals(0, $cache->get('foo/bar')->getSize());

$this->assertEquals(31, $cache->get('foo/bar')->getPermissions());
$this->assertEquals(false, $aclCache->get('foo/bar'));
}
}

0 comments on commit a6c2362

Please sign in to comment.