Cache: allow storage backends to overwrite Watcher

This commit is contained in:
Robin Appelman 2013-01-01 18:04:29 +01:00
parent f2ca7023e1
commit b41189de44
4 changed files with 21 additions and 9 deletions

View file

@ -249,6 +249,13 @@ abstract class Common implements \OC\Files\Storage\Storage {
return new \OC\Files\Cache\Permissions($this);
}
/**
* @return \OC\Files\Cache\Watcher
*/
public function getWatcher(){
return new \OC\Files\Cache\Watcher($this);
}
/**
* get the owner of a path
* @param string $path The path to get the owner

View file

@ -69,6 +69,11 @@ interface Storage{
*/
public function getPermissionsCache();
/**
* @return \OC\Files\Cache\Watcher
*/
public function getWatcher();
/**
* get the ETag for a file or folder
*

View file

@ -685,7 +685,7 @@ class View {
$scanner = $storage->getScanner();
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
} else {
$watcher = new \OC\Files\Cache\Watcher($storage);
$watcher = $storage->getWatcher();
$watcher->checkUpdate($internalPath);
}
@ -733,7 +733,7 @@ class View {
$scanner = $storage->getScanner();
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
} else {
$watcher = new \OC\Files\Cache\Watcher($storage);
$watcher = $storage->getWatcher();
$watcher->checkUpdate($internalPath);
}

View file

@ -32,7 +32,7 @@ class Watcher extends \PHPUnit_Framework_TestCase {
function testWatcher() {
$storage = $this->getTestStorage();
$cache = $storage->getCache();
$updater = new \OC\Files\Cache\Watcher($storage);
$updater = $storage->getWatcher();
//set the mtime to the past so it can detect an mtime change
$cache->put('', array('mtime' => 10));
@ -66,16 +66,16 @@ class Watcher extends \PHPUnit_Framework_TestCase {
public function testFileToFolder() {
$storage = $this->getTestStorage();
$cache = $storage->getCache();
$updater = new \OC\Files\Cache\Watcher($storage);
$updater = $storage->getWatcher();
//set the mtime to the past so it can detect an mtime change
$cache->put('', array('mtime' => 10));
$storage->unlink('foo.txt');
$storage->rename('folder','foo.txt');
$storage->rename('folder', 'foo.txt');
$updater->checkUpdate('');
$entry= $cache->get('foo.txt');
$entry = $cache->get('foo.txt');
$this->assertEquals(-1, $entry['size']);
$this->assertEquals('httpd/unix-directory', $entry['mimetype']);
$this->assertFalse($cache->inCache('folder'));
@ -83,16 +83,16 @@ class Watcher extends \PHPUnit_Framework_TestCase {
$storage = $this->getTestStorage();
$cache = $storage->getCache();
$updater = new \OC\Files\Cache\Watcher($storage);
$updater = $storage->getWatcher();
//set the mtime to the past so it can detect an mtime change
$cache->put('foo.txt', array('mtime' => 10));
$storage->unlink('foo.txt');
$storage->rename('folder','foo.txt');
$storage->rename('folder', 'foo.txt');
$updater->checkUpdate('foo.txt');
$entry= $cache->get('foo.txt');
$entry = $cache->get('foo.txt');
$this->assertEquals('httpd/unix-directory', $entry['mimetype']);
$this->assertTrue($cache->inCache('foo.txt/bar.txt'));
}