From 10be42f5b7b17ca55c242960885a9b50e217af3f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 19 Apr 2013 15:03:59 +0200 Subject: Cache: only look for child entires when doing a move operation when moving a folder --- lib/files/cache/cache.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 71b70abe3fe..d30c5cd16ed 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -205,7 +205,7 @@ class Cache { . ' VALUES(' . implode(', ', $valuesPlaceholder) . ')'); $result = $query->execute($params); if (\OC_DB::isError($result)) { - \OCP\Util::writeLog('cache', 'Insert to cache failed: '.$result, \OCP\Util::ERROR); + \OCP\Util::writeLog('cache', 'Insert to cache failed: ' . $result, \OCP\Util::ERROR); } return (int)\OC_DB::insertid('*PREFIX*filecache'); @@ -328,19 +328,22 @@ class Cache { * @param string $target */ public function move($source, $target) { - $sourceId = $this->getId($source); + $sourceData = $this->get($source); + $sourceId = $sourceData['fileid']; $newParentId = $this->getParentId($target); - //find all child entries - $query = \OC_DB::prepare('SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `path` LIKE ?'); - $result = $query->execute(array($source . '/%')); - $childEntries = $result->fetchAll(); - $sourceLength = strlen($source); - $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ? WHERE `fileid` = ?'); - - foreach ($childEntries as $child) { - $targetPath = $target . substr($child['path'], $sourceLength); - $query->execute(array($targetPath, md5($targetPath), $child['fileid'])); + if ($sourceData['mimetype'] === 'httpd/unix-directory') { + //find all child entries + $query = \OC_DB::prepare('SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `path` LIKE ?'); + $result = $query->execute(array($source . '/%')); + $childEntries = $result->fetchAll(); + $sourceLength = strlen($source); + $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ? WHERE `fileid` = ?'); + + foreach ($childEntries as $child) { + $targetPath = $target . substr($child['path'], $sourceLength); + $query->execute(array($targetPath, md5($targetPath), $child['fileid'])); + } } $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `name` = ?, `parent` =?' -- cgit v1.2.3 From 15dae6198fc4855519a0ed2347c29485a061f6aa Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 20 Apr 2013 16:38:03 +0200 Subject: Cache: add a backgroundjob to check for external changes to the filesystem --- apps/files/appinfo/app.php | 4 +- lib/files/cache/backgroundwatcher.php | 73 +++++++++++++++++++++++++++++++++++ lib/files/cache/cache.php | 1 + lib/files/cache/permissions.php | 15 +++++++ tests/lib/files/cache/permissions.php | 6 ++- 5 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 lib/files/cache/backgroundwatcher.php (limited to 'lib/files/cache') diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php index 703b1c7cb6c..05ab1722b3e 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -18,4 +18,6 @@ OC_Search::registerProvider('OC_Search_Provider_File'); \OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook'); \OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook'); \OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook'); -\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook'); \ No newline at end of file +\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook'); + +\OC_BackgroundJob_RegularTask::register('\OC\Files\Cache\BackgroundWatcher', 'checkNext'); diff --git a/lib/files/cache/backgroundwatcher.php b/lib/files/cache/backgroundwatcher.php new file mode 100644 index 00000000000..3bcd447f53a --- /dev/null +++ b/lib/files/cache/backgroundwatcher.php @@ -0,0 +1,73 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Cache; + +use \OC\Files\Mount; +use \OC\Files\Filesystem; + +class BackgroundWatcher { + static private function checkUpdate($id) { + $cacheItem = Cache::getById($id); + if (is_null($cacheItem)) { + return; + } + list($storageId, $internalPath) = $cacheItem; + $mounts = Mount::findByStorageId($storageId); + + if (count($mounts) === 0) { + //if the storage we need isn't mounted on default, try to find a user that has access to the storage + $permissionsCache = new Permissions($storageId); + $users = $permissionsCache->getUsers($id); + if (count($users) === 0) { + return; + } + Filesystem::initMountPoints($users[0]); + $mounts = Mount::findByStorageId($storageId); + if (count($mounts) === 0) { + return; + } + } + $storage = $mounts[0]->getStorage(); + $watcher = new Watcher($storage); + $watcher->checkUpdate($internalPath); + } + + /** + * get the next fileid in the cache + * + * @param int $previous + * @return int + */ + static private function getNextFileId($previous) { + $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? ORDER BY `fileid` ASC', 1); + $result = $query->execute(array($previous)); + if ($row = $result->fetchRow()) { + return $row['fileid']; + } else { + return 0; + } + } + + static public function checkNext() { + $previous = \OC_Appconfig::getValue('files', 'backgroundwatcher_previous', 0); + $next = self::getNextFileId($previous); + error_log($next); + \OC_Appconfig::setValue('files', 'backgroundwatcher_previous', $next); + self::checkUpdate($next); + } + + static public function checkAll() { + $previous = 0; + $next = 1; + while ($next != 0) { + $next = self::getNextFileId($previous); + self::checkUpdate($next); + } + } +} diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 71b70abe3fe..3ed3490f29b 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -517,6 +517,7 @@ class Cache { /** * get the storage id of the storage for a file and the internal path of the file * + * @param int $id * @return array, first element holding the storage id, second the path */ static public function getById($id) { diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php index a5c9c144054..faa5ff5eacc 100644 --- a/lib/files/cache/permissions.php +++ b/lib/files/cache/permissions.php @@ -107,4 +107,19 @@ class Permissions { $query->execute(array($fileId, $user)); } } + + /** + * get the list of users which have permissions stored for a file + * + * @param int $fileId + */ + public function getUsers($fileId) { + $query = \OC_DB::prepare('SELECT `user` FROM `*PREFIX*permissions` WHERE `fileid` = ?'); + $result = $query->execute(array($fileId)); + $users = array(); + while ($row = $result->fetchRow()) { + $users[] = $row['user']; + } + return $users; + } } diff --git a/tests/lib/files/cache/permissions.php b/tests/lib/files/cache/permissions.php index 56dbbc4518e..7e6e11e2eb2 100644 --- a/tests/lib/files/cache/permissions.php +++ b/tests/lib/files/cache/permissions.php @@ -14,8 +14,8 @@ class Permissions extends \PHPUnit_Framework_TestCase { */ private $permissionsCache; - function setUp(){ - $this->permissionsCache=new \OC\Files\Cache\Permissions('dummy'); + function setUp() { + $this->permissionsCache = new \OC\Files\Cache\Permissions('dummy'); } function testSimple() { @@ -23,8 +23,10 @@ class Permissions extends \PHPUnit_Framework_TestCase { $user = uniqid(); $this->assertEquals(-1, $this->permissionsCache->get(1, $user)); + $this->assertNotContains($user, $this->permissionsCache->getUsers(1)); $this->permissionsCache->set(1, $user, 1); $this->assertEquals(1, $this->permissionsCache->get(1, $user)); + $this->assertContains($user, $this->permissionsCache->getUsers(1)); $this->assertEquals(-1, $this->permissionsCache->get(2, $user)); $this->assertEquals(-1, $this->permissionsCache->get(1, $user . '2')); -- cgit v1.2.3 From eed5e9f804c0aac0467e1f502d86266ea232f350 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 20 Apr 2013 16:56:47 +0200 Subject: Cache: check one folder and one file each time the backgroundwatcher runs Because there are usually way less folders than files it walks trought the list of all folder quicker, this causes new files to be detected quicker --- lib/files/cache/backgroundwatcher.php | 47 +++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/backgroundwatcher.php b/lib/files/cache/backgroundwatcher.php index 3bcd447f53a..7549745e7d7 100644 --- a/lib/files/cache/backgroundwatcher.php +++ b/lib/files/cache/backgroundwatcher.php @@ -12,6 +12,18 @@ use \OC\Files\Mount; use \OC\Files\Filesystem; class BackgroundWatcher { + static $folderMimetype = null; + + static private function getFolderMimetype() { + if (!is_null(self::$folderMimetype)) { + return self::$folderMimetype; + } + $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?'); + $result = $query->execute(array('httpd/unix-directory')); + $row = $result->fetchRow(); + return $row['id']; + } + static private function checkUpdate($id) { $cacheItem = Cache::getById($id); if (is_null($cacheItem)) { @@ -42,10 +54,15 @@ class BackgroundWatcher { * get the next fileid in the cache * * @param int $previous + * @param bool $folder * @return int */ - static private function getNextFileId($previous) { - $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? ORDER BY `fileid` ASC', 1); + static private function getNextFileId($previous, $folder) { + if ($folder) { + $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND mimetype = ' . self::getFolderMimetype() . ' ORDER BY `fileid` ASC', 1); + } else { + $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND mimetype != ' . self::getFolderMimetype() . ' ORDER BY `fileid` ASC', 1); + } $result = $query->execute(array($previous)); if ($row = $result->fetchRow()) { return $row['fileid']; @@ -55,18 +72,32 @@ class BackgroundWatcher { } static public function checkNext() { - $previous = \OC_Appconfig::getValue('files', 'backgroundwatcher_previous', 0); - $next = self::getNextFileId($previous); - error_log($next); - \OC_Appconfig::setValue('files', 'backgroundwatcher_previous', $next); - self::checkUpdate($next); + // check both 1 file and 1 folder, this way new files are detected quicker because there are less folders than files usually + $previousFile = \OC_Appconfig::getValue('files', 'backgroundwatcher_previous_file', 0); + $previousFolder = \OC_Appconfig::getValue('files', 'backgroundwatcher_previous_folder', 0); + $nextFile = self::getNextFileId($previousFile, false); + $nextFolder = self::getNextFileId($previousFolder, true); + \OC_Appconfig::setValue('files', 'backgroundwatcher_previous_file', $nextFile); + \OC_Appconfig::setValue('files', 'backgroundwatcher_previous_folder', $nextFolder); + if ($nextFile > 0) { + self::checkUpdate($nextFile); + } + if ($nextFolder > 0) { + self::checkUpdate($nextFolder); + } } static public function checkAll() { $previous = 0; $next = 1; while ($next != 0) { - $next = self::getNextFileId($previous); + $next = self::getNextFileId($previous, true); + self::checkUpdate($next); + } + $previous = 0; + $next = 1; + while ($next != 0) { + $next = self::getNextFileId($previous, false); self::checkUpdate($next); } } -- cgit v1.2.3 From bcd9a6903317a786f5f947374a8680130e4a8297 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 26 Apr 2013 00:00:18 +0200 Subject: Cache: seperate handing of numeric storage id's to it's own class --- lib/files/cache/cache.php | 47 +++++++++++++--------------------- lib/files/cache/storage.php | 59 +++++++++++++++++++++++++++++++++++++++++++ lib/files/storage/common.php | 10 +++++++- lib/files/storage/storage.php | 5 ++++ 4 files changed, 91 insertions(+), 30 deletions(-) create mode 100644 lib/files/cache/storage.php (limited to 'lib/files/cache') diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 71b70abe3fe..857fe980be6 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -30,11 +30,9 @@ class Cache { private $storageId; /** - * numeric storage id - * - * @var int $numericId + * @var Storage $storageCache */ - private $numericId; + private $storageCache; private $mimetypeIds = array(); private $mimetypes = array(); @@ -52,19 +50,11 @@ class Cache { $this->storageId = md5($this->storageId); } - $query = \OC_DB::prepare('SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?'); - $result = $query->execute(array($this->storageId)); - if ($row = $result->fetchRow()) { - $this->numericId = $row['numeric_id']; - } else { - $query = \OC_DB::prepare('INSERT INTO `*PREFIX*storages`(`id`) VALUES(?)'); - $query->execute(array($this->storageId)); - $this->numericId = \OC_DB::insertid('*PREFIX*storages'); - } + $this->storageCache = new Storage($storage); } public function getNumericStorageId() { - return $this->numericId; + return $this->storageCache->getNumericId(); } /** @@ -111,7 +101,7 @@ class Cache { public function get($file) { if (is_string($file) or $file == '') { $where = 'WHERE `storage` = ? AND `path_hash` = ?'; - $params = array($this->numericId, md5($file)); + $params = array($this->getNumericStorageId(), md5($file)); } else { //file id $where = 'WHERE `fileid` = ?'; $params = array($file); @@ -198,14 +188,14 @@ class Cache { list($queryParts, $params) = $this->buildParts($data); $queryParts[] = '`storage`'; - $params[] = $this->numericId; + $params[] = $this->getNumericStorageId(); $valuesPlaceholder = array_fill(0, count($queryParts), '?'); $query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ')' . ' VALUES(' . implode(', ', $valuesPlaceholder) . ')'); $result = $query->execute($params); if (\OC_DB::isError($result)) { - \OCP\Util::writeLog('cache', 'Insert to cache failed: '.$result, \OCP\Util::ERROR); + \OCP\Util::writeLog('cache', 'Insert to cache failed: ' . $result, \OCP\Util::ERROR); } return (int)\OC_DB::insertid('*PREFIX*filecache'); @@ -264,7 +254,7 @@ class Cache { $pathHash = md5($file); $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'); - $result = $query->execute(array($this->numericId, $pathHash)); + $result = $query->execute(array($this->getNumericStorageId(), $pathHash)); if ($row = $result->fetchRow()) { return $row['fileid']; @@ -353,7 +343,7 @@ class Cache { */ public function clear() { $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage = ?'); - $query->execute(array($this->numericId)); + $query->execute(array($this->getNumericStorageId())); $query = \OC_DB::prepare('DELETE FROM `*PREFIX*storages` WHERE id = ?'); $query->execute(array($this->storageId)); @@ -367,7 +357,7 @@ class Cache { public function getStatus($file) { $pathHash = md5($file); $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'); - $result = $query->execute(array($this->numericId, $pathHash)); + $result = $query->execute(array($this->getNumericStorageId(), $pathHash)); if ($row = $result->fetchRow()) { if ((int)$row['size'] === -1) { return self::SHALLOW; @@ -394,7 +384,7 @@ class Cache { SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag` FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `storage` = ?' ); - $result = $query->execute(array($pattern, $this->numericId)); + $result = $query->execute(array($pattern, $this->getNumericStorageId())); $files = array(); while ($row = $result->fetchRow()) { $row['mimetype'] = $this->getMimetype($row['mimetype']); @@ -421,7 +411,7 @@ class Cache { FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?' ); $mimetype = $this->getMimetypeId($mimetype); - $result = $query->execute(array($mimetype, $this->numericId)); + $result = $query->execute(array($mimetype, $this->getNumericStorageId())); $files = array(); while ($row = $result->fetchRow()) { $row['mimetype'] = $this->getMimetype($row['mimetype']); @@ -459,7 +449,7 @@ class Cache { return 0; } $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?'); - $result = $query->execute(array($id, $this->numericId)); + $result = $query->execute(array($id, $this->getNumericStorageId())); $totalSize = 0; $hasChilds = 0; while ($row = $result->fetchRow()) { @@ -486,7 +476,7 @@ class Cache { */ public function getAll() { $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?'); - $result = $query->execute(array($this->numericId)); + $result = $query->execute(array($this->getNumericStorageId())); $ids = array(); while ($row = $result->fetchRow()) { $ids[] = $row['fileid']; @@ -506,7 +496,7 @@ class Cache { public function getIncomplete() { $query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache`' . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1'); - $result = $query->execute(array($this->numericId)); + $result = $query->execute(array($this->getNumericStorageId())); if ($row = $result->fetchRow()) { return $row['path']; } else { @@ -517,6 +507,7 @@ class Cache { /** * get the storage id of the storage for a file and the internal path of the file * + * @param int $id * @return array, first element holding the storage id, second the path */ static public function getById($id) { @@ -529,10 +520,8 @@ class Cache { return null; } - $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?'); - $result = $query->execute(array($numericId)); - if ($row = $result->fetchRow()) { - return array($row['id'], $path); + if ($id = Storage::getStorageId($numericId)) { + return array($id, $path); } else { return null; } diff --git a/lib/files/cache/storage.php b/lib/files/cache/storage.php new file mode 100644 index 00000000000..72de376798c --- /dev/null +++ b/lib/files/cache/storage.php @@ -0,0 +1,59 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Cache; + +/** + * Class Storage + * + * cache storage specific data + * + * @package OC\Files\Cache + */ +class Storage { + private $storageId; + private $numericId; + + /** + * @param \OC\Files\Storage\Storage|string $storage + */ + public function __construct($storage) { + if ($storage instanceof \OC\Files\Storage\Storage) { + $this->storageId = $storage->getId(); + } else { + $this->storageId = $storage; + } + if (strlen($this->storageId) > 64) { + $this->storageId = md5($this->storageId); + } + + $query = \OC_DB::prepare('SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?'); + $result = $query->execute(array($this->storageId)); + if ($row = $result->fetchRow()) { + $this->numericId = $row['numeric_id']; + } else { + $query = \OC_DB::prepare('INSERT INTO `*PREFIX*storages`(`id`) VALUES(?)'); + $query->execute(array($this->storageId)); + $this->numericId = \OC_DB::insertid('*PREFIX*storages'); + } + } + + public function getNumericId() { + return $this->numericId; + } + + public static function getStorageId($numericId) { + $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?'); + $result = $query->execute(array($numericId)); + if ($row = $result->fetchRow()) { + return $row['id']; + } else { + return null; + } + } +} diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index 38fe5e546f6..e87fe3b5239 100644 --- a/lib/files/storage/common.php +++ b/lib/files/storage/common.php @@ -25,6 +25,7 @@ abstract class Common implements \OC\Files\Storage\Storage { private $scanner; private $permissioncache; private $watcher; + private $storageCache; public function __construct($parameters) { } @@ -300,6 +301,13 @@ abstract class Common implements \OC\Files\Storage\Storage { return $this->watcher; } + public function getStorageCache(){ + if (!isset($this->storageCache)) { + $this->storageCache = new \OC\Files\Cache\Storage($this); + } + return $this->storageCache; + } + /** * get the owner of a path * @@ -361,7 +369,7 @@ abstract class Common implements \OC\Files\Storage\Storage { * get the free space in the storage * * @param $path - * return int + * @return int */ public function free_space($path) { return \OC\Files\FREE_SPACE_UNKNOWN; diff --git a/lib/files/storage/storage.php b/lib/files/storage/storage.php index 1da82da2163..c96caebf4af 100644 --- a/lib/files/storage/storage.php +++ b/lib/files/storage/storage.php @@ -328,6 +328,11 @@ interface Storage { */ public function getWatcher($path = ''); + /** + * @return \OC\Files\Cache\Storage + */ + public function getStorageCache(); + /** * get the ETag for a file or folder * -- cgit v1.2.3 From f55aaad858396484d35f87ca09e5f53e9848ddf6 Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Mon, 29 Apr 2013 15:43:48 +0200 Subject: fix for infinite loop causing on files_encryption branch when testing "apps/files_encryption/test/crypt.php" on Method testSymmetricStreamEncryptShortFileContent --- lib/files/cache/cache.php | 2 +- lib/files/cache/scanner.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 857fe980be6..47f3c272b13 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -430,7 +430,7 @@ class Cache { $this->calculateFolderSize($path); if ($path !== '') { $parent = dirname($path); - if ($parent === '.') { + if ($parent === '.' or $parent === '/') { $parent = ''; } $this->correctFolderSize($parent); diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index f019d4fc608..5241acec1ee 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -68,7 +68,7 @@ class Scanner { if ($data) { if ($file) { $parent = dirname($file); - if ($parent === '.') { + if ($parent === '.' or $parent === '/') { $parent = ''; } if (!$this->cache->inCache($parent)) { -- cgit v1.2.3 From 0e30e68b22bf3db2872dcff50fe1c0186aa1c57e Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 8 May 2013 15:49:45 +0200 Subject: update etag for for the touched file --- lib/files/cache/updater.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/updater.php b/lib/files/cache/updater.php index 92a16d9d9b6..e054b9dafcf 100644 --- a/lib/files/cache/updater.php +++ b/lib/files/cache/updater.php @@ -132,7 +132,15 @@ class Updater { * @param array $params */ static public function touchHook($params) { - self::writeUpdate($params['path']); + $path = $params['path']; + list($storage, $internalPath) = self::resolvePath($path); + $cache = $storage->getCache(); + $id = $cache->getId($internalPath); + if ($id !== -1) { + $cache->update($id, array('etag' => $storage->getETag($internalPath))); + self::correctFolder($parent, $time); + } + self::writeUpdate($path); } /** -- cgit v1.2.3 From 2e81efc37eeb95b7e5d392349ad393bb94d6928a Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 8 May 2013 22:57:08 +0200 Subject: don't call correctFolder() in touchHook, it will be called later in the writeUpdate() --- lib/files/cache/updater.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/updater.php b/lib/files/cache/updater.php index e054b9dafcf..417a47f3830 100644 --- a/lib/files/cache/updater.php +++ b/lib/files/cache/updater.php @@ -138,7 +138,6 @@ class Updater { $id = $cache->getId($internalPath); if ($id !== -1) { $cache->update($id, array('etag' => $storage->getETag($internalPath))); - self::correctFolder($parent, $time); } self::writeUpdate($path); } -- cgit v1.2.3 From c3b0d3d38cb2cfe1501a28081dde34dbec2d2621 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 10 May 2013 12:00:13 +0200 Subject: rename isIgnoredFile to isPartialFile, remove check of blacklisted files in isPartialFile, correct usage of isPartialFile and isFileBlacklisted --- lib/files/cache/scanner.php | 10 +++++----- lib/files/view.php | 16 +++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index 5241acec1ee..661bc486330 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -62,7 +62,9 @@ class Scanner { * @return array with metadata of the scanned file */ public function scanFile($file, $checkExisting = false) { - if (!self::isIgnoredFile($file)) { + if ( ! self::isPartialFile($file) + and ! \OC\Files\Filesystem::isFileBlacklisted($file) + ) { \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId)); $data = $this->getData($file); if ($data) { @@ -166,10 +168,8 @@ class Scanner { * @param String $file * @return boolean */ - public static function isIgnoredFile($file) { - if (pathinfo($file, PATHINFO_EXTENSION) === 'part' - || \OC\Files\Filesystem::isFileBlacklisted($file) - ) { + public static function isPartialFile($file) { + if (pathinfo($file, PATHINFO_EXTENSION) === 'part') { return true; } return false; diff --git a/lib/files/view.php b/lib/files/view.php index f89b7f66ffd..35053e0729c 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -263,12 +263,13 @@ class View { if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) - && Filesystem::isValidPath($path) + and Filesystem::isValidPath($path) + and ! Filesystem::isFileBlacklisted($path) ) { $path = $this->getRelativePath($absolutePath); $exists = $this->file_exists($path); $run = true; - if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isIgnoredFile($path)) { + if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path)) { if (!$exists) { \OC_Hook::emit( Filesystem::CLASSNAME, @@ -296,7 +297,7 @@ class View { list ($count, $result) = \OC_Helper::streamCopy($data, $target); fclose($target); fclose($data); - if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isIgnoredFile($path)) { + if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path)) { if (!$exists) { \OC_Hook::emit( Filesystem::CLASSNAME, @@ -340,6 +341,7 @@ class View { \OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2) and Filesystem::isValidPath($path2) and Filesystem::isValidPath($path1) + and ! Filesystem::isFileBlacklisted($path2) ) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); @@ -404,6 +406,7 @@ class View { \OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and Filesystem::isValidPath($path2) and Filesystem::isValidPath($path1) + and ! Filesystem::isFileBlacklisted($path2) ) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); @@ -606,7 +609,10 @@ class View { private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) { $postFix = (substr($path, -1, 1) === '/') ? '/' : ''; $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); - if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and Filesystem::isValidPath($path)) { + if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) + and Filesystem::isValidPath($path) + and ! Filesystem::isFileBlacklisted($path) + ) { $path = $this->getRelativePath($absolutePath); if ($path == null) { return false; @@ -635,7 +641,7 @@ class View { private function runHooks($hooks, $path, $post = false) { $prefix = ($post) ? 'post_' : ''; $run = true; - if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isIgnoredFile($path)) { + if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot()) { foreach ($hooks as $hook) { if ($hook != 'read') { \OC_Hook::emit( -- cgit v1.2.3