Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

triger the propagator from the command line scanner #24256

Merged
merged 1 commit into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@icewind1991 can you remind me whether this is debounced on the path ?

Because if we detect several changes within the same folder, it would be expensive to propagate the etag to the parents several times for every found file.

}
}

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());
}
}