[Pkg-owncloud-commits] [owncloud] 55/83: reuse etags when doing a background scan

David Prévot taffit at moszumanska.debian.org
Wed Dec 18 13:05:31 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch 5.0
in repository owncloud.

commit 605fa4a444cf2de5deee22e6e298e095eab4c20a
Author: Robin Appelman <icewind at owncloud.com>
Date:   Thu Dec 5 15:23:34 2013 +0100

    reuse etags when doing a background scan
---
 lib/files/cache/scanner.php  |  2 +-
 tests/lib/files/etagtest.php | 79 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 429685c..23d40fd 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -255,7 +255,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 0000000..b50a96a
--- /dev/null
+++ b/tests/lib/files/etagtest.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind at 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 testWithSharing() {
+		$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('/folder', '/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;
+	}
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list