From 38c563dcdcfc46742a55be3b9b84a37512e203d3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 9 Oct 2013 20:34:18 +0200 Subject: [PATCH] don't trigger the create hooks when if the file already exists for file_put_contents --- lib/private/files/view.php | 3 ++- tests/lib/files/view.php | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/private/files/view.php b/lib/private/files/view.php index aa08a5f7cc..f74b595c8d 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -324,7 +324,8 @@ class View { return false; } } else { - return $this->basicOperation('file_put_contents', $path, array('create', 'write'), $data); + $hooks = ($this->file_exists($path)) ? array('write') : array('create', 'write'); + return $this->basicOperation('file_put_contents', $path, $hooks, $data); } } diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 3043f132b7..a5107c351f 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -391,4 +391,29 @@ class View extends \PHPUnit_Framework_TestCase { $this->storages[] = $storage; return $storage; } + + private $createHookPath; + + function dummyCreateHook($params) { + $this->createHookPath = $params['path']; + } + + public function testEditNoCreateHook() { + $storage1 = $this->getTestStorage(); + $storage2 = $this->getTestStorage(); + $defaultRoot = \OC\Files\Filesystem::getRoot(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + \OC\Files\Filesystem::mount($storage2, array(), $defaultRoot); + \OC_Hook::connect('OC_Filesystem', 'post_create', $this, 'dummyCreateHook'); + + $view = new \OC\Files\View($defaultRoot); + $this->hookPath = null; + + $view->file_put_contents('/asd.txt', 'foo'); + $this->assertEquals('/asd.txt', $this->createHookPath); + $this->createHookPath = null; + + $view->file_put_contents('/asd.txt', 'foo'); + $this->assertNull($this->createHookPath); + } }