Merge pull request #2204 from owncloud/chache_updater_rename
Cache: better rename hook for cache updater
This commit is contained in:
commit
7f1ff3e9e1
|
@ -53,6 +53,30 @@ class Updater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function renameUpdate($from, $to) {
|
||||||
|
/**
|
||||||
|
* @var \OC\Files\Storage\Storage $storageFrom
|
||||||
|
* @var \OC\Files\Storage\Storage $storageTo
|
||||||
|
* @var string $internalFrom
|
||||||
|
* @var string $internalTo
|
||||||
|
*/
|
||||||
|
list($storageFrom, $internalFrom) = self::resolvePath($from);
|
||||||
|
list($storageTo, $internalTo) = self::resolvePath($to);
|
||||||
|
if ($storageFrom && $storageTo) {
|
||||||
|
if ($storageFrom === $storageTo) {
|
||||||
|
$cache = $storageFrom->getCache($internalFrom);
|
||||||
|
$cache->move($internalFrom, $internalTo);
|
||||||
|
$cache->correctFolderSize($internalFrom);
|
||||||
|
$cache->correctFolderSize($internalTo);
|
||||||
|
self::correctFolder($from, time());
|
||||||
|
self::correctFolder($to, time());
|
||||||
|
} else {
|
||||||
|
self::deleteUpdate($from);
|
||||||
|
self::writeUpdate($to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the mtime and ETag of all parent folders
|
* Update the mtime and ETag of all parent folders
|
||||||
*
|
*
|
||||||
|
@ -92,8 +116,7 @@ class Updater {
|
||||||
* @param array $params
|
* @param array $params
|
||||||
*/
|
*/
|
||||||
static public function renameHook($params) {
|
static public function renameHook($params) {
|
||||||
self::deleteUpdate($params['oldpath']);
|
self::renameUpdate($params['oldpath'], $params['newpath']);
|
||||||
self::writeUpdate($params['newpath']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -54,6 +54,8 @@ class Updater extends \PHPUnit_Framework_TestCase {
|
||||||
Filesystem::clearMounts();
|
Filesystem::clearMounts();
|
||||||
Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
|
Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
|
||||||
|
|
||||||
|
\OC_Hook::clear('OC_Filesystem');
|
||||||
|
|
||||||
\OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook');
|
\OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook');
|
||||||
\OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook');
|
\OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook');
|
||||||
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook');
|
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook');
|
||||||
|
@ -137,11 +139,10 @@ class Updater extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertFalse($this->cache->inCache('foo.txt'));
|
$this->assertFalse($this->cache->inCache('foo.txt'));
|
||||||
$this->assertTrue($this->cache->inCache('bar.txt'));
|
$this->assertTrue($this->cache->inCache('bar.txt'));
|
||||||
$cachedData = $this->cache->get('bar.txt');
|
$cachedData = $this->cache->get('bar.txt');
|
||||||
$this->assertNotEquals($fooCachedData['etag'], $cachedData['etag']);
|
$this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']);
|
||||||
$mtime = $cachedData['mtime'];
|
$mtime = $cachedData['mtime'];
|
||||||
$cachedData = $this->cache->get('');
|
$cachedData = $this->cache->get('');
|
||||||
$this->assertEquals(3 * $textSize + $imageSize, $cachedData['size']);
|
$this->assertEquals(3 * $textSize + $imageSize, $cachedData['size']);
|
||||||
$this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
|
$this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
|
||||||
$this->assertEquals($mtime, $cachedData['mtime']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue