diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-04-30 13:57:44 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-04-30 13:57:44 +0200 |
commit | 4481a8412c28f57baece09f12a9589179cc5de8a (patch) | |
tree | 0de0ed695912225cadb4463108509ec026e435ac /lib | |
parent | 654a6e6c6a0128b5443f7668ab6905523c049614 (diff) | |
parent | ced2a4fcf283985a09698bdc5164c039b3996bbc (diff) | |
download | nextcloud-server-4481a8412c28f57baece09f12a9589179cc5de8a.tar.gz nextcloud-server-4481a8412c28f57baece09f12a9589179cc5de8a.zip |
Merge pull request #8132 from owncloud/issue/8131
Issue/8131 Fix emitting of filesystem related hooks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/filesystem.php | 16 | ||||
-rw-r--r-- | lib/private/files/view.php | 118 |
2 files changed, 57 insertions, 77 deletions
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index 434ee495870..52df1bec611 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -119,6 +119,22 @@ class Filesystem { const signal_post_write = 'post_write'; /** + * signal emitted before file/dir update + * + * @param string $path + * @param bool $run changing this flag to false in hook handler will cancel event + */ + const signal_update = 'update'; + + /** + * signal emitted after file/dir update + * + * @param string $path + * @param bool $run changing this flag to false in hook handler will cancel event + */ + const signal_post_update = 'post_update'; + + /** * signal emits when reading file/dir * * @param string $path diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 31ec8cfacff..47fc04c937d 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -271,6 +271,39 @@ class View { return $this->basicOperation('file_get_contents', $path, array('read')); } + protected function emit_file_hooks_pre($exists, $path, &$run) { + if (!$exists) { + \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_create, array( + Filesystem::signal_param_path => $this->getHookPath($path), + Filesystem::signal_param_run => &$run, + )); + } else { + \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_update, array( + Filesystem::signal_param_path => $this->getHookPath($path), + Filesystem::signal_param_run => &$run, + )); + } + \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_write, array( + Filesystem::signal_param_path => $this->getHookPath($path), + Filesystem::signal_param_run => &$run, + )); + } + + protected function emit_file_hooks_post($exists, $path) { + if (!$exists) { + \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_create, array( + Filesystem::signal_param_path => $this->getHookPath($path), + )); + } else { + \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_update, array( + Filesystem::signal_param_path => $this->getHookPath($path), + )); + } + \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_write, array( + Filesystem::signal_param_path => $this->getHookPath($path), + )); + } + public function file_put_contents($path, $data) { if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); @@ -282,24 +315,7 @@ class View { $exists = $this->file_exists($path); $run = true; if ($this->shouldEmitHooks($path)) { - if (!$exists) { - \OC_Hook::emit( - Filesystem::CLASSNAME, - Filesystem::signal_create, - array( - Filesystem::signal_param_path => $this->getHookPath($path), - Filesystem::signal_param_run => &$run - ) - ); - } - \OC_Hook::emit( - Filesystem::CLASSNAME, - Filesystem::signal_write, - array( - Filesystem::signal_param_path => $this->getHookPath($path), - Filesystem::signal_param_run => &$run - ) - ); + $this->emit_file_hooks_pre($exists, $path, $run); } if (!$run) { return false; @@ -313,18 +329,7 @@ class View { Updater::writeHook(array( 'path' => $this->getHookPath($path) )); - if (!$exists) { - \OC_Hook::emit( - Filesystem::CLASSNAME, - Filesystem::signal_post_create, - array(Filesystem::signal_param_path => $this->getHookPath($path)) - ); - } - \OC_Hook::emit( - Filesystem::CLASSNAME, - Filesystem::signal_post_write, - array(Filesystem::signal_param_path => $this->getHookPath($path)) - ); + $this->emit_file_hooks_post($exists, $path); } \OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count); return $result; @@ -335,7 +340,7 @@ class View { return false; } } else { - $hooks = ($this->file_exists($path)) ? array('write') : array('create', 'write'); + $hooks = ($this->file_exists($path)) ? array('update', 'write') : array('create', 'write'); return $this->basicOperation('file_put_contents', $path, $hooks, $data); } } @@ -378,6 +383,7 @@ class View { ) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); + $exists = $this->file_exists($path2); if ($path1 == null or $path2 == null) { return false; @@ -385,13 +391,7 @@ class View { $run = true; if ($this->shouldEmitHooks() && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) { // if it was a rename from a part file to a regular file it was a write and not a rename operation - \OC_Hook::emit( - Filesystem::CLASSNAME, Filesystem::signal_write, - array( - Filesystem::signal_param_path => $this->getHookPath($path2), - Filesystem::signal_param_run => &$run - ) - ); + $this->emit_file_hooks_pre($exists, $path2, $run); } elseif ($this->shouldEmitHooks()) { \OC_Hook::emit( Filesystem::CLASSNAME, Filesystem::signal_rename, @@ -448,13 +448,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, - array( - Filesystem::signal_param_path => $this->getHookPath($path2), - ) - ); + $this->emit_file_hooks_post($exists, $path2); } elseif ($this->shouldEmitHooks() && $result !== false) { Updater::renameHook(array( 'oldpath' => $this->getHookPath($path1), @@ -507,26 +501,7 @@ class View { Filesystem::signal_param_run => &$run ) ); - if ($run and !$exists) { - \OC_Hook::emit( - Filesystem::CLASSNAME, - Filesystem::signal_create, - array( - Filesystem::signal_param_path => $this->getHookPath($path2), - Filesystem::signal_param_run => &$run - ) - ); - } - if ($run) { - \OC_Hook::emit( - Filesystem::CLASSNAME, - Filesystem::signal_write, - array( - Filesystem::signal_param_path => $this->getHookPath($path2), - Filesystem::signal_param_run => &$run - ) - ); - } + $this->emit_file_hooks_pre($exists, $path2, $run); } if ($run) { $mp1 = $this->getMountPoint($path1 . $postFix1); @@ -566,18 +541,7 @@ class View { Filesystem::signal_param_newpath => $this->getHookPath($path2) ) ); - if (!$exists) { - \OC_Hook::emit( - Filesystem::CLASSNAME, - Filesystem::signal_post_create, - array(Filesystem::signal_param_path => $this->getHookPath($path2)) - ); - } - \OC_Hook::emit( - Filesystem::CLASSNAME, - Filesystem::signal_post_write, - array(Filesystem::signal_param_path => $this->getHookPath($path2)) - ); + $this->emit_file_hooks_post($exists, $path2); } return $result; } else { |