summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Karlitschek <frank@owncloud.org>2013-03-17 05:03:18 -0700
committerFrank Karlitschek <frank@owncloud.org>2013-03-17 05:03:18 -0700
commit7f1ff3e9e1253dd6c3be658d139db1c87104be3c (patch)
tree778e1be8d44b255e7a4c21fbc22717f717d76b66
parent86f6938c38f05c52a391988ea17a54e1f19be203 (diff)
parent1d3beffacf70519d5d9c49b3a7af18faae99a6c4 (diff)
downloadnextcloud-server-7f1ff3e9e1253dd6c3be658d139db1c87104be3c.tar.gz
nextcloud-server-7f1ff3e9e1253dd6c3be658d139db1c87104be3c.zip
Merge pull request #2204 from owncloud/chache_updater_rename
Cache: better rename hook for cache updater
-rw-r--r--lib/files/cache/updater.php43
-rw-r--r--tests/lib/files/cache/updater.php5
2 files changed, 36 insertions, 12 deletions
diff --git a/lib/files/cache/updater.php b/lib/files/cache/updater.php
index d04541c219f..e760ba71bc6 100644
--- a/lib/files/cache/updater.php
+++ b/lib/files/cache/updater.php
@@ -53,12 +53,36 @@ 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
- *
- * @param string $path
- * @param string $time
- */
+ * Update the mtime and ETag of all parent folders
+ *
+ * @param string $path
+ * @param string $time
+ */
static public function correctFolder($path, $time) {
if ($path !== '' && $path !== '/') {
$parent = dirname($path);
@@ -66,9 +90,9 @@ class Updater {
$parent = '';
}
/**
- * @var \OC\Files\Storage\Storage $storage
- * @var string $internalPath
- */
+ * @var \OC\Files\Storage\Storage $storage
+ * @var string $internalPath
+ */
list($storage, $internalPath) = self::resolvePath($parent);
if ($storage) {
$cache = $storage->getCache();
@@ -92,8 +116,7 @@ class Updater {
* @param array $params
*/
static public function renameHook($params) {
- self::deleteUpdate($params['oldpath']);
- self::writeUpdate($params['newpath']);
+ self::renameUpdate($params['oldpath'], $params['newpath']);
}
/**
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index 7a79f45a203..aaf932c97fe 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -54,6 +54,8 @@ class Updater extends \PHPUnit_Framework_TestCase {
Filesystem::clearMounts();
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_delete', '\OC\Files\Cache\Updater', 'deleteHook');
\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->assertTrue($this->cache->inCache('bar.txt'));
$cachedData = $this->cache->get('bar.txt');
- $this->assertNotEquals($fooCachedData['etag'], $cachedData['etag']);
+ $this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']);
$mtime = $cachedData['mtime'];
$cachedData = $this->cache->get('');
$this->assertEquals(3 * $textSize + $imageSize, $cachedData['size']);
$this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
- $this->assertEquals($mtime, $cachedData['mtime']);
}
}