use unmasked permissions during scanning
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
cd2b567c21
commit
1f1e1b0d00
|
@ -266,6 +266,9 @@ class Scanner extends BasicEmitter implements IScanner {
|
||||||
* @return int the id of the added file
|
* @return int the id of the added file
|
||||||
*/
|
*/
|
||||||
protected function addToCache($path, $data, $fileId = -1) {
|
protected function addToCache($path, $data, $fileId = -1) {
|
||||||
|
if (isset($data['scan_permissions'])) {
|
||||||
|
$data['permissions'] = $data['scan_permissions'];
|
||||||
|
}
|
||||||
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $path, 'data' => $data));
|
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $path, 'data' => $data));
|
||||||
$this->emit('\OC\Files\Cache\Scanner', 'addToCache', array($path, $this->storageId, $data));
|
$this->emit('\OC\Files\Cache\Scanner', 'addToCache', array($path, $this->storageId, $data));
|
||||||
if ($this->cacheActive) {
|
if ($this->cacheActive) {
|
||||||
|
|
|
@ -40,6 +40,7 @@ class CachePermissionsMask extends CacheWrapper {
|
||||||
|
|
||||||
protected function formatCacheEntry($entry) {
|
protected function formatCacheEntry($entry) {
|
||||||
if (isset($entry['permissions'])) {
|
if (isset($entry['permissions'])) {
|
||||||
|
$entry['scan_permissions'] = $entry['permissions'];
|
||||||
$entry['permissions'] &= $this->mask;
|
$entry['permissions'] &= $this->mask;
|
||||||
}
|
}
|
||||||
return $entry;
|
return $entry;
|
||||||
|
|
|
@ -143,7 +143,8 @@ class PermissionsMask extends Wrapper {
|
||||||
$data = parent::getMetaData($path);
|
$data = parent::getMetaData($path);
|
||||||
|
|
||||||
if ($data && isset($data['permissions'])) {
|
if ($data && isset($data['permissions'])) {
|
||||||
$data['permissions'] = $data['permissions'] & $this->mask;
|
$data['scan_permissions'] = $data['permissions'];
|
||||||
|
$data['permissions'] &= $this->mask;
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
|
|
||||||
namespace Test\Files\Storage\Wrapper;
|
namespace Test\Files\Storage\Wrapper;
|
||||||
|
|
||||||
|
use OC\Files\Storage\Wrapper\Wrapper;
|
||||||
use OCP\Constants;
|
use OCP\Constants;
|
||||||
|
use OCP\Files\Cache\IScanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group DB
|
* @group DB
|
||||||
|
@ -114,4 +116,49 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
|
||||||
$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $this->sourceStorage->getCache()->get('foo')->getPermissions());
|
$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $this->sourceStorage->getCache()->get('foo')->getPermissions());
|
||||||
$this->assertEquals(Constants::PERMISSION_READ, $storage->getCache()->get('foo')->getPermissions());
|
$this->assertEquals(Constants::PERMISSION_READ, $storage->getCache()->get('foo')->getPermissions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testScanNewWrappedFiles() {
|
||||||
|
$storage = $this->getMaskedStorage(Constants::PERMISSION_READ + Constants::PERMISSION_CREATE);
|
||||||
|
$wrappedStorage = new Wrapper(['storage' => $storage]);
|
||||||
|
$wrappedStorage->file_put_contents('foo', 'bar');
|
||||||
|
$wrappedStorage->getScanner()->scan('');
|
||||||
|
|
||||||
|
$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $this->sourceStorage->getCache()->get('foo')->getPermissions());
|
||||||
|
$this->assertEquals(Constants::PERMISSION_READ, $storage->getCache()->get('foo')->getPermissions());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanUnchanged() {
|
||||||
|
$this->sourceStorage->mkdir('foo');
|
||||||
|
$this->sourceStorage->file_put_contents('foo/bar.txt', 'bar');
|
||||||
|
|
||||||
|
$this->sourceStorage->getScanner()->scan('foo');
|
||||||
|
|
||||||
|
$storage = $this->getMaskedStorage(Constants::PERMISSION_READ);
|
||||||
|
$scanner = $storage->getScanner();
|
||||||
|
$called = false;
|
||||||
|
$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function () use (&$called) {
|
||||||
|
$called = true;
|
||||||
|
});
|
||||||
|
$scanner->scan('foo', IScanner::SCAN_RECURSIVE, IScanner::REUSE_ETAG | IScanner::REUSE_SIZE);
|
||||||
|
|
||||||
|
$this->assertFalse($called);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanUnchangedWrapped() {
|
||||||
|
$this->sourceStorage->mkdir('foo');
|
||||||
|
$this->sourceStorage->file_put_contents('foo/bar.txt', 'bar');
|
||||||
|
|
||||||
|
$this->sourceStorage->getScanner()->scan('foo');
|
||||||
|
|
||||||
|
$storage = $this->getMaskedStorage(Constants::PERMISSION_READ);
|
||||||
|
$wrappedStorage = new Wrapper(['storage' => $storage]);
|
||||||
|
$scanner = $wrappedStorage->getScanner();
|
||||||
|
$called = false;
|
||||||
|
$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function () use (&$called) {
|
||||||
|
$called = true;
|
||||||
|
});
|
||||||
|
$scanner->scan('foo', IScanner::SCAN_RECURSIVE, IScanner::REUSE_ETAG | IScanner::REUSE_SIZE);
|
||||||
|
|
||||||
|
$this->assertFalse($called);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue