diff options
author | Vincent Petry <pvince81@owncloud.com> | 2013-12-06 10:13:14 -0800 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2013-12-06 10:13:14 -0800 |
commit | 123bc9921a0369582b547cd3d8abc7d466d1f7f3 (patch) | |
tree | 8ecf889e916454361af4ae4f057030f3f738ac3d | |
parent | 575a68074fbaa9614ad746bf589d843998a2cb3c (diff) | |
parent | 9eca2471b3e8b75c21a1a8fd2a88c20c577c07bc (diff) | |
download | nextcloud-server-123bc9921a0369582b547cd3d8abc7d466d1f7f3.tar.gz nextcloud-server-123bc9921a0369582b547cd3d8abc7d466d1f7f3.zip |
Merge pull request #6201 from owncloud/backgroundscan-reuse-etag
reuse etags when doing a background scan
-rwxr-xr-x[-rw-r--r--] | config/config.sample.php | 0 | ||||
-rw-r--r-- | lib/private/files/cache/scanner.php | 2 | ||||
-rw-r--r-- | tests/lib/files/etagtest.php | 79 | ||||
-rw-r--r-- | tests/lib/files/filesystem.php | 48 |
4 files changed, 104 insertions, 25 deletions
diff --git a/config/config.sample.php b/config/config.sample.php index ba068968323..ba068968323 100644..100755 --- a/config/config.sample.php +++ b/config/config.sample.php diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index 34184c68c64..a8c069ee99f 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -286,7 +286,7 @@ class Scanner extends BasicEmitter { public function backgroundScan() { $lastPath = null; while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { - $this->scan($path); + $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG); $this->cache->correctFolderSize($path); $lastPath = $path; } diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php new file mode 100644 index 00000000000..6c41413c4df --- /dev/null +++ b/tests/lib/files/etagtest.php @@ -0,0 +1,79 @@ +<?php +/** + * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Files; + +use OC\Files\Filesystem; +use OCP\Share; + +class EtagTest extends \PHPUnit_Framework_TestCase { + private $datadir; + + private $tmpDir; + + private $uid; + + /** + * @var \OC_User_Dummy $userBackend + */ + private $userBackend; + + public function setUp() { + \OC_Hook::clear('OC_Filesystem', 'setup'); + \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); + \OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); + \OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file'); + + $this->datadir = \OC_Config::getValue('datadirectory'); + $this->tmpDir = \OC_Helper::tmpFolder(); + \OC_Config::setValue('datadirectory', $this->tmpDir); + $this->uid = \OC_User::getUser(); + \OC_User::setUserId(null); + + $this->userBackend = new \OC_User_Dummy(); + \OC_User::useBackend($this->userBackend); + \OC_Util::tearDownFS(); + } + + public function tearDown() { + \OC_Config::setValue('datadirectory', $this->datadir); + \OC_User::setUserId($this->uid); + \OC_Util::setupFS($this->uid); + } + + public function testNewUser() { + $user1 = uniqid('user_'); + $this->userBackend->createUser($user1, ''); + + \OC_Util::tearDownFS(); + \OC_User::setUserId($user1); + \OC_Util::setupFS($user1); + Filesystem::mkdir('/folder'); + Filesystem::mkdir('/folder/subfolder'); + Filesystem::file_put_contents('/foo.txt', 'asd'); + Filesystem::file_put_contents('/folder/bar.txt', 'fgh'); + Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl'); + + $files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt'); + $originalEtags = $this->getEtags($files); + + $scanner = new \OC\Files\Utils\Scanner($user1); + $scanner->backgroundScan('/'); + + $this->assertEquals($originalEtags, $this->getEtags($files)); + } + + private function getEtags($files) { + $etags = array(); + foreach ($files as $file) { + $info = Filesystem::getFileInfo($file); + $etags[$file] = $info['etag']; + } + return $etags; + } +} diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index 7cb57bf95ad..90f1dfe581b 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -26,7 +26,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase { /** * @var array tmpDirs */ - private $tmpDirs=array(); + private $tmpDirs = array(); /** * @return array @@ -51,21 +51,21 @@ class Filesystem extends \PHPUnit_Framework_TestCase { } public function testMount() { - \OC\Files\Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/'); - $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/')); - $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/some/folder')); - list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/'); - $this->assertEquals('',$internalPath); - list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder'); - $this->assertEquals('some/folder',$internalPath); - - \OC\Files\Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/some'); - $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/')); - $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/folder')); - $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/')); - $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some')); - list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder'); - $this->assertEquals('folder',$internalPath); + \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/'); + $this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/')); + $this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/some/folder')); + list(, $internalPath) = \OC\Files\Filesystem::resolvePath('/'); + $this->assertEquals('', $internalPath); + list(, $internalPath) = \OC\Files\Filesystem::resolvePath('/some/folder'); + $this->assertEquals('some/folder', $internalPath); + + \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/some'); + $this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/')); + $this->assertEquals('/some/', \OC\Files\Filesystem::getMountPoint('/some/folder')); + $this->assertEquals('/some/', \OC\Files\Filesystem::getMountPoint('/some/')); + $this->assertEquals('/some/', \OC\Files\Filesystem::getMountPoint('/some')); + list(, $internalPath) = \OC\Files\Filesystem::resolvePath('/some/folder'); + $this->assertEquals('folder', $internalPath); } public function testNormalize() { @@ -136,20 +136,20 @@ class Filesystem extends \PHPUnit_Framework_TestCase { } public function testHooks() { - if(\OC\Files\Filesystem::getView()){ + if (\OC\Files\Filesystem::getView()) { $user = \OC_User::getUser(); - }else{ - $user=uniqid(); - \OC\Files\Filesystem::init($user, '/'.$user.'/files'); + } else { + $user = uniqid(); + \OC\Files\Filesystem::init($user, '/' . $user . '/files'); } \OC_Hook::clear('OC_Filesystem'); \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook'); \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); - $rootView=new \OC\Files\View(''); - $rootView->mkdir('/'.$user); - $rootView->mkdir('/'.$user.'/files'); + $rootView = new \OC\Files\View(''); + $rootView->mkdir('/' . $user); + $rootView->mkdir('/' . $user . '/files'); // \OC\Files\Filesystem::file_put_contents('/foo', 'foo'); \OC\Files\Filesystem::mkdir('/bar'); @@ -215,7 +215,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase { $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/'); $this->assertInstanceOf('\OC\Files\Storage\Home', $homeMount); - $this->assertEquals('local::' . $datadir. '/' . $userId . '/', $homeMount->getId()); + $this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId()); \OC_User::deleteUser($userId); // delete storage entry |