Skip to content

Commit

Permalink
Merge pull request #24256 from owncloud/scanner-propagate
Browse files Browse the repository at this point in the history
triger the propagator from the command line scanner
  • Loading branch information
MorrisJobke committed Apr 26, 2016
2 parents ef8fc6a + 61054df commit 23e7ad7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/private/Files/Utils/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OC\ForbiddenException;
use OC\Hooks\PublicEmitter;
use OC\Lock\DBLockingProvider;
use OCP\Files\Storage\IStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\ILogger;

Expand Down Expand Up @@ -153,6 +154,17 @@ public function scan($dir = '') {
$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();
}
Expand All @@ -168,5 +180,9 @@ public function scan($dir = '') {
}
}
}

private function triggerPropagator(IStorage $storage, $internalPath) {
$storage->getPropagator()->propagateChange($internalPath, time());
}
}

24 changes: 24 additions & 0 deletions tests/lib/files/utils/scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,28 @@ public function testInvalidPathScanning($invalidPath) {
$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());
}
}

0 comments on commit 23e7ad7

Please sign in to comment.