From bc49c6be04d78740d9b7cb100debcb6641559d39 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 26 Feb 2014 14:29:13 +0100 Subject: [PATCH 1/4] Manually triger the filecache update hooks before any other hook --- apps/files/appinfo/app.php | 7 ------- lib/private/files/view.php | 20 ++++++++++++++++++++ tests/lib/files/cache/updater.php | 5 ----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php index 909baca92ea..15a29133789 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -12,13 +12,6 @@ OCP\App::addNavigationEntry(array("id" => "files_index", OC_Search::registerProvider('OC_Search_Provider_File'); -// cache hooks must be connected before all other apps. -// since 'files' is always loaded first the hooks need to be connected here -\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'); - \OCP\BackgroundJob::addRegularTask('\OC\Files\Cache\BackgroundWatcher', 'checkNext'); $templateManager = OC_Helper::getFileTemplateManager(); diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 2dbbf5b88c9..a76115a816e 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -25,6 +25,8 @@ namespace OC\Files; +use OC\Files\Cache\Updater; + class View { private $fakeRoot = ''; private $internal_path_cache = array(); @@ -433,6 +435,7 @@ class View { } if ($this->shouldEmitHooks() && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) { // if it was a rename from a part file to a regular file it was a write and not a rename operation + Updater::writeHook(array('path' => $this->getHookPath($path2))); \OC_Hook::emit( Filesystem::CLASSNAME, Filesystem::signal_post_write, @@ -441,6 +444,10 @@ class View { ) ); } elseif ($this->shouldEmitHooks() && $result !== false) { + Updater::renameHook(array( + 'oldpath' => $this->getHookPath($path1), + 'newpath' => $this->getHookPath($path2) + )); \OC_Hook::emit( Filesystem::CLASSNAME, Filesystem::signal_post_rename, @@ -741,7 +748,10 @@ class View { } /** + * @param string[] $hooks * @param string $path + * @param bool $post + * @return bool */ private function runHooks($hooks, $path, $post = false) { $path = $this->getHookPath($path); @@ -749,6 +759,16 @@ class View { $run = true; if ($this->shouldEmitHooks($path)) { foreach ($hooks as $hook) { + // manually triger updater hooks to ensure they are called first + if ($post) { + if ($hook == 'write') { + Updater::writeHook(array('path' => $path)); + } elseif ($hook == 'touch') { + Updater::touchHook(array('path' => $path)); + } else if ($hook == 'delete') { + Updater::deleteHook(array('path' => $path)); + } + } if ($hook != 'read') { \OC_Hook::emit( Filesystem::CLASSNAME, diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 48986149a73..1c4c965af0b 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -65,11 +65,6 @@ class Updater extends \PHPUnit_Framework_TestCase { Filesystem::mount($this->storage, array(), '/' . self::$user . '/files'); \OC_Hook::clear('OC_Filesystem'); - - \OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook'); - \OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook'); - \OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook'); - \OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook'); } public function tearDown() { From 3ff12ef4eca82325a6e4f1244a12597174e07192 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 28 Feb 2014 14:21:33 +0100 Subject: [PATCH 2/4] Also send explicit cache hooks when calling file_put_contents with a resource --- lib/private/files/view.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/files/view.php b/lib/private/files/view.php index a76115a816e..975b5d00099 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -310,6 +310,9 @@ class View { fclose($target); fclose($data); if ($this->shouldEmitHooks($path) && $result !== false) { + Updater::writeHook(array( + 'path' => $this->getHookPath($path) + )); if (!$exists) { \OC_Hook::emit( Filesystem::CLASSNAME, From c87658fedab5073642848b2db0e8707dc2b5cff4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 3 Mar 2014 12:56:08 +0100 Subject: [PATCH 3/4] Fix updater when getFileInfo fails --- lib/private/files/cache/updater.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 7a45b9e9e96..f6ea914bf62 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -119,6 +119,9 @@ class Updater { if ($uid != \OCP\User::getUser()) { $info = \OC\Files\Filesystem::getFileInfo($filename); + if (!$info) { + return array($uid, '/files/' . $filename); + } $ownerView = new \OC\Files\View('/' . $uid . '/files'); $filename = $ownerView->getPath($info['fileid']); } @@ -150,7 +153,7 @@ class Updater { $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath))); if ($realPath !== '') { $realPath = dirname($realPath); - if($realPath === DIRECTORY_SEPARATOR ) { + if ($realPath === DIRECTORY_SEPARATOR) { $realPath = ""; } // check storage for parent in case we change the storage in this step From 895fc0fa26ee5a1e9dbadb09736dbb56cad0c6e8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 6 Mar 2014 14:23:27 +0100 Subject: [PATCH 4/4] Fix check if fileinfo is valid --- lib/private/files/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 975b5d00099..f06c2fcd66c 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -843,7 +843,7 @@ class View { $data = $cache->get($internalPath); } - if ($data and $data['fileid']) { + if ($data and isset($data['fileid'])) { if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') { //add the sizes of other mountpoints to the folder $mountPoints = Filesystem::getMountPoints($path);