From b3626f34cd0df127d742f7a8cb2a4ddf929ff886 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 29 Oct 2013 14:18:57 +0100 Subject: [PATCH 1/2] Update the parent folders storage_mtime on write and delete to prevent rescans --- lib/private/files/cache/updater.php | 22 +++++++++++++++++++- tests/lib/files/cache/updater.php | 32 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 1f30173a8f..b491b60b0d 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -7,6 +7,7 @@ */ namespace OC\Files\Cache; + use OCP\Util; /** @@ -42,6 +43,7 @@ class Updater { $scanner->scan($internalPath, Scanner::SCAN_SHALLOW); $cache->correctFolderSize($internalPath); self::correctFolder($path, $storage->filemtime($internalPath)); + self::correctParentStorageMtime($storage, $internalPath); } } @@ -61,6 +63,7 @@ class Updater { $cache->remove($internalPath); $cache->correctFolderSize($internalPath); self::correctFolder($path, time()); + self::correctParentStorageMtime($storage, $internalPath); } } @@ -87,6 +90,8 @@ class Updater { $cache->correctFolderSize($internalTo); self::correctFolder($from, time()); self::correctFolder($to, time()); + self::correctParentStorageMtime($storageFrom, $internalFrom); + self::correctParentStorageMtime($storageTo, $internalTo); } else { self::deleteUpdate($from); self::writeUpdate($to); @@ -118,12 +123,27 @@ class Updater { $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath))); self::correctFolder($parent, $time); } else { - Util::writeLog('core', 'Path not in cache: '.$internalPath, Util::ERROR); + Util::writeLog('core', 'Path not in cache: ' . $internalPath, Util::ERROR); } } } } + /** + * update the storage_mtime of the parent + * + * @param \OC\Files\Storage\Storage $storage + * @param string $internalPath + */ + static private function correctParentStorageMtime($storage, $internalPath) { + $cache = $storage->getCache(); + $parentId = $cache->getParentId($internalPath); + $parent = dirname($internalPath); + if ($parentId != -1) { + $cache->update($parentId, array('storage_mtime' => $storage->filemtime($parent))); + } + } + /** * @param array $params */ diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 5d7997b054..a891f2560c 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -9,6 +9,7 @@ namespace Test\Files\Cache; use \OC\Files\Filesystem as Filesystem; +use OC\Files\Storage\Temporary; class Updater extends \PHPUnit_Framework_TestCase { /** @@ -265,4 +266,35 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->assertEquals($time, $cachedData['mtime']); } + public function testUpdatePermissionsOnRescanOnlyForUpdatedFile() { + $permissionsCache = $this->storage->getPermissionsCache(); + $scanner = $this->storage->getScanner(); + $scanner->scan(''); + $cache = $this->storage->getCache(); + $loggedInUser = \OC_User::getUser(); + \OC_User::setUserId(self::$user); + FileSystem::getDirectoryContent('/'); + $past = time() - 600; + $cache->put('', array('storage_mtime' => $past)); + + $this->assertNotEquals(-1, $permissionsCache->get($cache->getId('foo.txt'), self::$user)); + $this->assertNotEquals(-1, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + $permissionsCache->set($cache->getId('foo.png'), self::$user, 15); + FileSystem::file_put_contents('/foo.txt', 'asd'); + + $this->assertEquals(-1, $permissionsCache->get($cache->getId('foo.txt'), self::$user)); + $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + FileSystem::getDirectoryContent('/'); + + $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + FileSystem::file_put_contents('/qwerty.txt', 'asd'); + FileSystem::getDirectoryContent('/'); + + $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + \OC_User::setUserId($loggedInUser); + } } From 654b0daf0145b216d81347325b17cf522a49ec81 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 29 Oct 2013 14:22:13 +0100 Subject: [PATCH 2/2] update touch tests for updated behaviour --- tests/lib/files/cache/updater.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index a891f2560c..d8414dadbe 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -234,7 +234,6 @@ class Updater extends \PHPUnit_Framework_TestCase { $cachedData = $this->cache->get('folder'); $this->assertNotEquals($folderCachedData['etag'], $cachedData['etag']); - $this->assertEquals($time, $cachedData['mtime']); $cachedData = $this->cache->get(''); $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']); @@ -259,7 +258,6 @@ class Updater extends \PHPUnit_Framework_TestCase { $cachedData = $cache2->get(''); $this->assertNotEquals($substorageCachedData['etag'], $cachedData['etag']); - $this->assertEquals($time, $cachedData['mtime']); $cachedData = $this->cache->get('folder'); $this->assertNotEquals($folderCachedData['etag'], $cachedData['etag']);