Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] Revert: don't apply acls when scanning #2836

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
}
}
Loading