From 1397d9a93c0b86f412688825871cbbe8b841f9b5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 25 Apr 2016 17:23:48 +0200 Subject: [PATCH] triger the propagator from the command line scanner --- lib/private/files/utils/scanner.php | 16 ++++++++++++++++ tests/lib/files/utils/scanner.php | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/private/files/utils/scanner.php b/lib/private/files/utils/scanner.php index 0652658389..b013cbecab 100644 --- a/lib/private/files/utils/scanner.php +++ b/lib/private/files/utils/scanner.php @@ -29,6 +29,7 @@ use OC\Files\Filesystem; use OC\ForbiddenException; use OC\Hooks\PublicEmitter; use OC\Lock\DBLockingProvider; +use OCP\Files\Storage\IStorage; use OCP\Files\StorageNotAvailableException; use OCP\ILogger; @@ -153,6 +154,17 @@ class Scanner extends PublicEmitter { $scanner->setUseTransactions(false); $this->attachListener($mount); $isDbLocking = \OC::$server->getLockingProvider() instanceof DBLockingProvider; + + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { + $this->triggerPropagator($storage, $path); + }); + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { + $this->triggerPropagator($storage, $path); + }); + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { + $this->triggerPropagator($storage, $path); + }); + if (!$isDbLocking) { $this->db->beginTransaction(); } @@ -168,5 +180,9 @@ class Scanner extends PublicEmitter { } } } + + private function triggerPropagator(IStorage $storage, $internalPath) { + $storage->getPropagator()->propagateChange($internalPath, time()); + } } diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php index 7779e2778c..1220c57e96 100644 --- a/tests/lib/files/utils/scanner.php +++ b/tests/lib/files/utils/scanner.php @@ -163,4 +163,28 @@ class Scanner extends \Test\TestCase { $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->scan($invalidPath); } + + public function testPropagateEtag() { + $storage = new Temporary(array()); + $mount = new MountPoint($storage, ''); + Filesystem::getMountManager()->addMount($mount); + $cache = $storage->getCache(); + + $storage->mkdir('folder'); + $storage->file_put_contents('folder/bar.txt', 'qwerty'); + $storage->touch('folder/bar.txt', time() - 200); + + $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); + $scanner->addMount($mount); + + $scanner->scan(''); + $this->assertTrue($cache->inCache('folder/bar.txt')); + $oldRoot = $cache->get(''); + + $storage->file_put_contents('folder/bar.txt', 'qwerty'); + $scanner->scan(''); + $newRoot = $cache->get(''); + + $this->assertNotEquals($oldRoot->getEtag(), $newRoot->getEtag()); + } }