]> source.dussan.org Git - nextcloud-server.git/commitdiff
don't trigger the create hooks when if the file already exists for file_put_contents
authorRobin Appelman <icewind@owncloud.com>
Wed, 9 Oct 2013 18:34:18 +0000 (20:34 +0200)
committerRobin Appelman <icewind@owncloud.com>
Wed, 9 Oct 2013 18:34:18 +0000 (20:34 +0200)
lib/private/files/view.php
tests/lib/files/view.php

index aa08a5f7cc9f2ad48ec756068283281850ff6d22..f74b595c8daedee2866757f4073e7fa3c76c2a0e 100644 (file)
@@ -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);
                }
        }
 
index 3043f132b73ea118af1e7bcd1f6e4f752c613f70..a5107c351f4468c5a3ba95f2fbdffb37e5852254 100644 (file)
@@ -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);
+       }
 }