diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-04-01 15:12:59 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-04-13 17:10:01 +0200 |
commit | d7b3a1a35a47dd37f68f7819aa0789b794e352e5 (patch) | |
tree | 79b377310bb6b8b3b822889aabc345d43ca974c8 /tests/lib/files | |
parent | a88e013f722a2bf30100074760509613c76ca807 (diff) | |
download | nextcloud-server-d7b3a1a35a47dd37f68f7819aa0789b794e352e5.tar.gz nextcloud-server-d7b3a1a35a47dd37f68f7819aa0789b794e352e5.zip |
preserve cache data when doing a cross storage move
Diffstat (limited to 'tests/lib/files')
-rw-r--r-- | tests/lib/files/cache/updater.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 7c3ebd5a6f9..726ee360479 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -172,4 +172,78 @@ class Updater extends \Test\TestCase { $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); } + + public function testMoveCrossStorage() { + $storage2 = new Temporary(array()); + $cache2 = $storage2->getCache(); + Filesystem::mount($storage2, array(), '/bar'); + $this->storage->file_put_contents('foo.txt', 'qwerty'); + + $this->updater->update('foo.txt'); + + $this->assertTrue($this->cache->inCache('foo.txt')); + $this->assertFalse($cache2->inCache('bar.txt')); + $cached = $this->cache->get('foo.txt'); + + // "rename" + $storage2->file_put_contents('bar.txt', 'qwerty'); + $this->storage->unlink('foo.txt'); + + $this->assertTrue($this->cache->inCache('foo.txt')); + $this->assertFalse($cache2->inCache('bar.txt')); + + $this->updater->rename('foo.txt', 'bar/bar.txt'); + + $this->assertFalse($this->cache->inCache('foo.txt')); + $this->assertTrue($cache2->inCache('bar.txt')); + + $cachedTarget = $cache2->get('bar.txt'); + $this->assertEquals($cached['mtime'], $cachedTarget['mtime']); + $this->assertEquals($cached['size'], $cachedTarget['size']); + $this->assertEquals($cached['etag'], $cachedTarget['etag']); + $this->assertEquals($cached['fileid'], $cachedTarget['fileid']); + } + + public function testMoveFolderCrossStorage() { + $storage2 = new Temporary(array()); + $cache2 = $storage2->getCache(); + Filesystem::mount($storage2, array(), '/bar'); + $this->storage->mkdir('foo'); + $this->storage->mkdir('foo/bar'); + $this->storage->file_put_contents('foo/foo.txt', 'qwerty'); + $this->storage->file_put_contents('foo/bar.txt', 'foo'); + $this->storage->file_put_contents('foo/bar/bar.txt', 'qwertyuiop'); + + $this->storage->getScanner()->scan(''); + + $this->assertTrue($this->cache->inCache('foo/foo.txt')); + $this->assertTrue($this->cache->inCache('foo/bar.txt')); + $this->assertTrue($this->cache->inCache('foo/bar/bar.txt')); + $cached = []; + $cached[] = $this->cache->get('foo/foo.txt'); + $cached[] = $this->cache->get('foo/bar.txt'); + $cached[] = $this->cache->get('foo/bar/bar.txt'); + + $this->view->rename('/foo', '/bar/foo'); + + $this->assertFalse($this->cache->inCache('foo/foo.txt')); + $this->assertFalse($this->cache->inCache('foo/bar.txt')); + $this->assertFalse($this->cache->inCache('foo/bar/bar.txt')); + $this->assertTrue($cache2->inCache('foo/foo.txt')); + $this->assertTrue($cache2->inCache('foo/bar.txt')); + $this->assertTrue($cache2->inCache('foo/bar/bar.txt')); + + $cachedTarget = []; + $cachedTarget[] = $cache2->get('foo/foo.txt'); + $cachedTarget[] = $cache2->get('foo/bar.txt'); + $cachedTarget[] = $cache2->get('foo/bar/bar.txt'); + + foreach ($cached as $i => $old) { + $new = $cachedTarget[$i]; + $this->assertEquals($old['mtime'], $new['mtime']); + $this->assertEquals($old['size'], $new['size']); + $this->assertEquals($old['etag'], $new['etag']); + $this->assertEquals($old['fileid'], $new['fileid']); + } + } } |