summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-06-02 15:17:00 +0200
committerRobin Appelman <icewind@owncloud.com>2014-06-02 15:24:08 +0200
commite002ff60658f675dba038aca8f682080b71d6ece (patch)
tree6093a99495cfc614bb7a4105bef9183a98637c2b
parent0158788a2a07a9eef9689c9d252659eedf852083 (diff)
downloadnextcloud-server-e002ff60658f675dba038aca8f682080b71d6ece.tar.gz
nextcloud-server-e002ff60658f675dba038aca8f682080b71d6ece.zip
propagate changes in the scanner
-rw-r--r--lib/private/files/cache/scanner.php1
-rw-r--r--lib/private/files/utils/scanner.php21
-rw-r--r--tests/lib/files/utils/scanner.php56
3 files changed, 77 insertions, 1 deletions
diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php
index 9beb582a0e8..bc2931c68d0 100644
--- a/lib/private/files/cache/scanner.php
+++ b/lib/private/files/cache/scanner.php
@@ -189,6 +189,7 @@ class Scanner extends BasicEmitter {
*/
protected function updateCache($path, $data) {
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $path, 'data' => $data));
+ $this->emit('\OC\Files\Cache\Scanner', 'updateCache', array($path, $this->storageId, $data));
if ($this->cacheActive) {
$this->cache->put($path, $data);
}
diff --git a/lib/private/files/utils/scanner.php b/lib/private/files/utils/scanner.php
index a802a8fcb8b..1bb3e694c96 100644
--- a/lib/private/files/utils/scanner.php
+++ b/lib/private/files/utils/scanner.php
@@ -8,6 +8,8 @@
namespace OC\Files\Utils;
+use OC\Files\View;
+use OC\Files\Cache\ChangePropagator;
use OC\Files\Filesystem;
use OC\Hooks\PublicEmitter;
@@ -27,10 +29,16 @@ class Scanner extends PublicEmitter {
private $user;
/**
+ * @var \OC\Files\Cache\ChangePropagator
+ */
+ protected $propagator;
+
+ /**
* @param string $user
*/
public function __construct($user) {
$this->user = $user;
+ $this->propagator = new ChangePropagator(new View(''));
}
/**
@@ -67,6 +75,15 @@ class Scanner extends PublicEmitter {
$scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) {
$emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path));
});
+
+ // propagate etag and mtimes when files are changed or removed
+ $propagator = $this->propagator;
+ $propagatorListener = function ($path) use ($mount, $propagator) {
+ $fullPath = Filesystem::normalizePath($mount->getMountPoint() . $path);
+ $propagator->addChange($fullPath);
+ };
+ $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', $propagatorListener);
+ $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', $propagatorListener);
}
/**
@@ -82,6 +99,7 @@ class Scanner extends PublicEmitter {
$this->attachListener($mount);
$scanner->backgroundScan();
}
+ $this->propagator->propagateChanges(time());
}
/**
@@ -95,8 +113,9 @@ class Scanner extends PublicEmitter {
}
$scanner = $mount->getStorage()->getScanner();
$this->attachListener($mount);
- $scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG);
+ $scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
}
+ $this->propagator->propagateChanges(time());
}
}
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
index a021d215ae5..4610e2b4d46 100644
--- a/tests/lib/files/utils/scanner.php
+++ b/tests/lib/files/utils/scanner.php
@@ -8,6 +8,7 @@
namespace Test\Files\Utils;
+use OC\Files\Filesystem;
use OC\Files\Mount\Mount;
use OC\Files\Storage\Temporary;
@@ -27,6 +28,14 @@ class TestScanner extends \OC\Files\Utils\Scanner {
protected function getMounts($dir) {
return $this->mounts;
}
+
+ public function getPropagator() {
+ return $this->propagator;
+ }
+
+ public function setPropagator($propagator) {
+ $this->propagator = $propagator;
+ }
}
class Scanner extends \PHPUnit_Framework_TestCase {
@@ -71,4 +80,51 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$new = $cache->get('folder/bar.txt');
$this->assertEquals($old, $new);
}
+
+ public function testChangePropagator() {
+ /**
+ * @var \OC\Files\Cache\ChangePropagator $propagator
+ */
+ $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false);
+
+ $storage = new Temporary(array());
+ $mount = new Mount($storage, '/foo');
+ Filesystem::getMountManager()->addMount($mount);
+ $cache = $storage->getCache();
+
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', 'qwerty');
+ $storage->file_put_contents('folder/bar.txt', 'qwerty');
+
+ $scanner = new TestScanner('');
+ $originalPropagator = $scanner->getPropagator();
+ $scanner->setPropagator($propagator);
+ $scanner->addMount($mount);
+
+ $scanner->scan('');
+
+ $this->assertEquals(array('/foo', '/foo/foo.txt', '/foo/folder', '/foo/folder/bar.txt'), $propagator->getChanges());
+ $this->assertEquals(array('/', '/foo', '/foo/folder'), $propagator->getAllParents());
+
+ $cache->put('foo.txt', array('mtime' => time() - 50));
+
+ $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false);
+ $scanner->setPropagator($propagator);
+ $storage->file_put_contents('foo.txt', 'asdasd');
+
+ $scanner->scan('');
+
+ $this->assertEquals(array('/foo/foo.txt'), $propagator->getChanges());
+ $this->assertEquals(array('/', '/foo'), $propagator->getAllParents());
+
+ $scanner->setPropagator($originalPropagator);
+
+ $oldInfo = $cache->get('');
+ $cache->put('foo.txt', array('mtime' => time() - 70));
+ $storage->file_put_contents('foo.txt', 'asdasd');
+
+ $scanner->scan('');
+ $newInfo = $cache->get('');
+ $this->assertNotEquals($oldInfo['etag'], $newInfo['etag']);
+ }
}