summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-10-29 11:57:00 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-10-29 11:57:00 +0100
commit530f7229e77d731eead7f1dc74296c62856a345b (patch)
treecfd16bf0803c7f575c57f116bbab0df9b4374eff
parent9ab44f1f00715e3c4c0fe2fb6a25846e6fc7495b (diff)
parentf355d4e51a1b597d4e763a10e3ebadb925b0c779 (diff)
downloadnextcloud-server-530f7229e77d731eead7f1dc74296c62856a345b.tar.gz
nextcloud-server-530f7229e77d731eead7f1dc74296c62856a345b.zip
Merge pull request #19869 from owncloud/cache-adjustcurrentmtimeonrename
On rename, also refresh storage_mtime of the target file
-rw-r--r--lib/private/files/cache/cache.php10
-rw-r--r--lib/private/files/cache/updater.php14
-rw-r--r--tests/lib/files/cache/updater.php41
-rw-r--r--tests/lib/files/view.php12
4 files changed, 74 insertions, 3 deletions
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index f3e22701f40..231dbe37695 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -313,6 +313,14 @@ class Cache {
$fields = array(
'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted',
'etag', 'permissions');
+
+ $doNotCopyStorageMTime = false;
+ if (array_key_exists('mtime', $data) && $data['mtime'] === null) {
+ // this horrific magic tells it to not copy storage_mtime to mtime
+ unset($data['mtime']);
+ $doNotCopyStorageMTime = true;
+ }
+
$params = array();
$queryParts = array();
foreach ($data as $name => $value) {
@@ -325,7 +333,7 @@ class Cache {
$queryParts[] = '`mimepart`';
$value = $this->mimetypeLoader->getId($value);
} elseif ($name === 'storage_mtime') {
- if (!isset($data['mtime'])) {
+ if (!$doNotCopyStorageMTime && !isset($data['mtime'])) {
$params[] = $value;
$queryParts[] = '`mtime`';
}
diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php
index 4cc5f511565..85dcc8589de 100644
--- a/lib/private/files/cache/updater.php
+++ b/lib/private/files/cache/updater.php
@@ -194,12 +194,26 @@ class Updater {
$targetCache->correctFolderSize($targetInternalPath);
$this->correctParentStorageMtime($sourceStorage, $sourceInternalPath);
$this->correctParentStorageMtime($targetStorage, $targetInternalPath);
+ $this->updateStorageMTimeOnly($targetStorage, $targetInternalPath);
$this->propagator->addChange($source);
$this->propagator->addChange($target);
$this->propagator->propagateChanges();
}
}
+ private function updateStorageMTimeOnly($storage, $internalPath) {
+ $cache = $storage->getCache();
+ $fileId = $cache->getId($internalPath);
+ if ($fileId !== -1) {
+ $cache->update(
+ $fileId, [
+ 'mtime' => null, // this magic tells it to not overwrite mtime
+ 'storage_mtime' => $storage->filemtime($internalPath)
+ ]
+ );
+ }
+ }
+
/**
* update the storage_mtime of the direct parent in the cache to the mtime from the storage
*
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index e3fa26829b4..b7e76aeace4 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -161,6 +161,47 @@ class Updater extends \Test\TestCase {
$this->assertEquals($cached['fileid'], $cachedTarget['fileid']);
}
+ public function testUpdateStorageMTime() {
+ $this->storage->mkdir('sub');
+ $this->storage->mkdir('sub2');
+ $this->storage->file_put_contents('sub/foo.txt', 'qwerty');
+
+ $this->updater->update('sub');
+ $this->updater->update('sub/foo.txt');
+ $this->updater->update('sub2');
+
+ $cachedSourceParent = $this->cache->get('sub');
+ $cachedSource = $this->cache->get('sub/foo.txt');
+
+ $this->storage->rename('sub/foo.txt', 'sub2/bar.txt');
+
+ // simulate storage having a different mtime
+ $testmtime = 1433323578;
+
+ // source storage mtime change
+ $this->storage->touch('sub', $testmtime);
+
+ // target storage mtime change
+ $this->storage->touch('sub2', $testmtime);
+ // some storages (like Dropbox) change storage mtime on rename
+ $this->storage->touch('sub2/bar.txt', $testmtime);
+
+ $this->updater->rename('sub/foo.txt', 'sub2/bar.txt');
+
+ $cachedTargetParent = $this->cache->get('sub2');
+ $cachedTarget = $this->cache->get('sub2/bar.txt');
+
+ $this->assertEquals($cachedSource['mtime'], $cachedTarget['mtime'], 'file mtime preserved');
+
+ $this->assertNotEquals($cachedTarget['storage_mtime'], $cachedTarget['mtime'], 'mtime is not storage_mtime for moved file');
+
+ $this->assertEquals($testmtime, $cachedTarget['storage_mtime'], 'target file storage_mtime propagated');
+ $this->assertNotEquals($testmtime, $cachedTarget['mtime'], 'target file mtime changed, not from storage');
+
+ $this->assertEquals($testmtime, $cachedTargetParent['storage_mtime'], 'target parent storage_mtime propagated');
+ $this->assertNotEquals($testmtime, $cachedTargetParent['mtime'], 'target folder mtime changed, not from storage');
+ }
+
public function testNewFileDisabled() {
$this->storage->file_put_contents('foo.txt', 'bar');
$this->assertFalse($this->cache->inCache('foo.txt'));
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index a84b8badd5a..a7979146b85 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -1976,9 +1976,13 @@ class View extends \Test\TestCase {
$view = new \OC\Files\View('/' . $this->user . '/files/');
$storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
- ->setMethods([$operation])
+ ->setMethods([$operation, 'filemtime'])
->getMock();
+ $storage->expects($this->any())
+ ->method('filemtime')
+ ->will($this->returnValue(123456789));
+
$sourcePath = 'original.txt';
$targetPath = 'target.txt';
@@ -2117,9 +2121,13 @@ class View extends \Test\TestCase {
->setMethods([$storageOperation])
->getMock();
$storage2 = $this->getMockBuilder('\OC\Files\Storage\Temporary')
- ->setMethods([$storageOperation])
+ ->setMethods([$storageOperation, 'filemtime'])
->getMock();
+ $storage2->expects($this->any())
+ ->method('filemtime')
+ ->will($this->returnValue(123456789));
+
$sourcePath = 'original.txt';
$targetPath = 'substorage/target.txt';