diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-05-19 00:49:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-19 00:49:58 +0200 |
commit | 8c624bdef9f3d7c2304ba4a3fba9dbbb23c65f3e (patch) | |
tree | d674313e168717c412d576e059ed16609271c96c | |
parent | 0eb4970ec8981d112a412a4858833459533b158a (diff) | |
parent | 1f1e1b0d000488ac6a7032ae2ba8ba7e25232b22 (diff) | |
download | nextcloud-server-8c624bdef9f3d7c2304ba4a3fba9dbbb23c65f3e.tar.gz nextcloud-server-8c624bdef9f3d7c2304ba4a3fba9dbbb23c65f3e.zip |
Merge pull request #4792 from nextcloud/fix-storage-wrappers-on-scanner
Make sure we use the passed-in storage when there is one
4 files changed, 57 insertions, 2 deletions
diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php index fe25da6d09a..229c6fc7d66 100644 --- a/lib/private/Files/Cache/Scanner.php +++ b/lib/private/Files/Cache/Scanner.php @@ -266,6 +266,9 @@ class Scanner extends BasicEmitter implements IScanner { * @return int the id of the added file */ 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)); $this->emit('\OC\Files\Cache\Scanner', 'addToCache', array($path, $this->storageId, $data)); if ($this->cacheActive) { diff --git a/lib/private/Files/Cache/Wrapper/CachePermissionsMask.php b/lib/private/Files/Cache/Wrapper/CachePermissionsMask.php index 83cf01045a7..6125887fb83 100644 --- a/lib/private/Files/Cache/Wrapper/CachePermissionsMask.php +++ b/lib/private/Files/Cache/Wrapper/CachePermissionsMask.php @@ -40,6 +40,7 @@ class CachePermissionsMask extends CacheWrapper { protected function formatCacheEntry($entry) { if (isset($entry['permissions'])) { + $entry['scan_permissions'] = $entry['permissions']; $entry['permissions'] &= $this->mask; } return $entry; diff --git a/lib/private/Files/Storage/Wrapper/PermissionsMask.php b/lib/private/Files/Storage/Wrapper/PermissionsMask.php index d66390dad49..1bda92f13aa 100644 --- a/lib/private/Files/Storage/Wrapper/PermissionsMask.php +++ b/lib/private/Files/Storage/Wrapper/PermissionsMask.php @@ -143,12 +143,16 @@ class PermissionsMask extends Wrapper { $data = parent::getMetaData($path); if ($data && isset($data['permissions'])) { - $data['permissions'] = $data['permissions'] & $this->mask; + $data['scan_permissions'] = $data['permissions']; + $data['permissions'] &= $this->mask; } return $data; } public function getScanner($path = '', $storage = null) { - return parent::getScanner($path, $this->storage); + if (!$storage) { + $storage = $this->storage; + } + return parent::getScanner($path, $storage); } } diff --git a/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php b/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php index d0903ce5f97..354db9d069d 100644 --- a/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php +++ b/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php @@ -8,7 +8,9 @@ namespace Test\Files\Storage\Wrapper; +use OC\Files\Storage\Wrapper\Wrapper; use OCP\Constants; +use OCP\Files\Cache\IScanner; /** * @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_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); + } } |