diff options
-rw-r--r-- | lib/private/files/cache/changepropagator.php | 4 | ||||
-rw-r--r-- | tests/lib/files/cache/changepropagator.php | 27 | ||||
-rw-r--r-- | tests/lib/files/cache/updaterlegacy.php | 2 |
3 files changed, 29 insertions, 4 deletions
diff --git a/lib/private/files/cache/changepropagator.php b/lib/private/files/cache/changepropagator.php index 2967c8f6259..36fc6e80144 100644 --- a/lib/private/files/cache/changepropagator.php +++ b/lib/private/files/cache/changepropagator.php @@ -59,8 +59,8 @@ class ChangePropagator { list($storage, $internalPath) = $this->view->resolvePath($parent); if ($storage) { $cache = $storage->getCache(); - $id = $cache->getId($internalPath); - $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath))); + $entry = $cache->get($internalPath); + $cache->update($entry['fileid'], array('mtime' => max($time, $entry['mtime']), 'etag' => $storage->getETag($internalPath))); } } } diff --git a/tests/lib/files/cache/changepropagator.php b/tests/lib/files/cache/changepropagator.php index 89bd9dfe80a..1b56da5e97c 100644 --- a/tests/lib/files/cache/changepropagator.php +++ b/tests/lib/files/cache/changepropagator.php @@ -23,12 +23,17 @@ class ChangePropagator extends \Test\TestCase { */ private $view; + /** + * @var \OC\Files\Storage\Storage + */ + private $storage; + protected function setUp() { parent::setUp(); - $storage = new Temporary(array()); + $this->storage = new Temporary(array()); $root = $this->getUniqueID('/'); - Filesystem::mount($storage, array(), $root); + Filesystem::mount($this->storage, array(), $root); $this->view = new View($root); $this->propagator = new \OC\Files\Cache\ChangePropagator($this->view); } @@ -71,4 +76,22 @@ class ChangePropagator extends \Test\TestCase { $this->assertNotSame($oldInfo2->getEtag(), $newInfo2->getEtag()); $this->assertNotSame($oldInfo3->getEtag(), $newInfo3->getEtag()); } + + public function testDontLowerMtime() { + $time = time(); + $this->view->mkdir('/foo'); + $this->view->mkdir('/foo/bar'); + + $cache = $this->storage->getCache(); + $cache->put('', ['mtime' => $time - 50]); + $cache->put('foo', ['mtime' => $time - 150]); + $cache->put('foo/bar', ['mtime' => $time - 250]); + + $this->propagator->addChange('/foo/bar/foo'); + $this->propagator->propagateChanges($time - 100); + + $this->assertEquals(50, $time - $cache->get('')['mtime']); + $this->assertEquals(100, $time - $cache->get('foo')['mtime']); + $this->assertEquals(100, $time - $cache->get('foo/bar')['mtime']); + } } diff --git a/tests/lib/files/cache/updaterlegacy.php b/tests/lib/files/cache/updaterlegacy.php index 7cf4dc6df5f..99cacca8e95 100644 --- a/tests/lib/files/cache/updaterlegacy.php +++ b/tests/lib/files/cache/updaterlegacy.php @@ -284,6 +284,7 @@ class UpdaterLegacy extends \Test\TestCase { $time = 1371006070; $barCachedData = $this->cache->get('folder/bar.txt'); $folderCachedData = $this->cache->get('folder'); + $this->cache->put('', ['mtime' => $time - 100]); Filesystem::touch('folder/bar.txt', $time); $cachedData = $this->cache->get('folder/bar.txt'); $this->assertInternalType('string', $barCachedData['etag']); @@ -314,6 +315,7 @@ class UpdaterLegacy extends \Test\TestCase { $fooCachedData = $cache2->get('foo.txt'); $cachedData = $cache2->get('foo.txt'); $time = 1371006070; + $this->cache->put('folder', ['mtime' => $time - 100]); Filesystem::touch('folder/substorage/foo.txt', $time); $cachedData = $cache2->get('foo.txt'); $this->assertInternalType('string', $fooCachedData['etag']); |