diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-03-21 18:02:30 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-03-21 18:02:30 +0100 |
commit | beef371398b1f70f017a26f95632ac497b6532e3 (patch) | |
tree | f7596dd51a5e4a86f4fd1706951c5edb844560e8 /apps | |
parent | 492a1ded1ce9c8151354054e8aa8ea8cdc2f4a5b (diff) | |
parent | f28f5380295b16d89f81994fc990924b8f15fa20 (diff) | |
download | nextcloud-server-beef371398b1f70f017a26f95632ac497b6532e3.tar.gz nextcloud-server-beef371398b1f70f017a26f95632ac497b6532e3.zip |
Merge pull request #23292 from owncloud/dav-chunking-onlyfirehooksonce
Do not fire pre/post hooks twice on chunk upload
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/connector/sabre/file.php | 4 | ||||
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/file.php | 69 |
2 files changed, 71 insertions, 2 deletions
diff --git a/apps/dav/lib/connector/sabre/file.php b/apps/dav/lib/connector/sabre/file.php index 59b3a6e7483..6b698c6e5a9 100644 --- a/apps/dav/lib/connector/sabre/file.php +++ b/apps/dav/lib/connector/sabre/file.php @@ -433,7 +433,7 @@ class File extends Node implements IFile { list($partStorage, $partInternalPath) = $this->fileView->resolvePath($partFile); - $chunk_handler->file_assemble($partStorage, $partInternalPath, $this->fileView->getAbsolutePath($targetPath)); + $chunk_handler->file_assemble($partStorage, $partInternalPath); // here is the final atomic rename $renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath); @@ -452,7 +452,7 @@ class File extends Node implements IFile { } } else { // assemble directly into the final file - $chunk_handler->file_assemble($targetStorage, $targetInternalPath, $this->fileView->getAbsolutePath($targetPath)); + $chunk_handler->file_assemble($targetStorage, $targetInternalPath); } // allow sync clients to send the mtime along in a header diff --git a/apps/dav/tests/unit/connector/sabre/file.php b/apps/dav/tests/unit/connector/sabre/file.php index 8bbef225483..eab7ece159c 100644 --- a/apps/dav/tests/unit/connector/sabre/file.php +++ b/apps/dav/tests/unit/connector/sabre/file.php @@ -422,6 +422,75 @@ class File extends \Test\TestCase { ); } + /** + * Test that putting a file with chunks triggers create hooks + */ + public function testPutChunkedFileTriggersHooks() { + HookHelper::setUpHooks(); + + $_SERVER['HTTP_OC_CHUNKED'] = true; + $this->assertNull($this->doPut('/foo.txt-chunking-12345-2-0')); + $this->assertNotEmpty($this->doPut('/foo.txt-chunking-12345-2-1')); + + $this->assertCount(4, HookHelper::$hookCalls); + $this->assertHookCall( + HookHelper::$hookCalls[0], + Filesystem::signal_create, + '/foo.txt' + ); + $this->assertHookCall( + HookHelper::$hookCalls[1], + Filesystem::signal_write, + '/foo.txt' + ); + $this->assertHookCall( + HookHelper::$hookCalls[2], + Filesystem::signal_post_create, + '/foo.txt' + ); + $this->assertHookCall( + HookHelper::$hookCalls[3], + Filesystem::signal_post_write, + '/foo.txt' + ); + } + + /** + * Test that putting a chunked file triggers update hooks + */ + public function testPutOverwriteChunkedFileTriggersHooks() { + $view = \OC\Files\Filesystem::getView(); + $view->file_put_contents('/foo.txt', 'some content that will be replaced'); + + HookHelper::setUpHooks(); + + $_SERVER['HTTP_OC_CHUNKED'] = true; + $this->assertNull($this->doPut('/foo.txt-chunking-12345-2-0')); + $this->assertNotEmpty($this->doPut('/foo.txt-chunking-12345-2-1')); + + $this->assertCount(4, HookHelper::$hookCalls); + $this->assertHookCall( + HookHelper::$hookCalls[0], + Filesystem::signal_update, + '/foo.txt' + ); + $this->assertHookCall( + HookHelper::$hookCalls[1], + Filesystem::signal_write, + '/foo.txt' + ); + $this->assertHookCall( + HookHelper::$hookCalls[2], + Filesystem::signal_post_update, + '/foo.txt' + ); + $this->assertHookCall( + HookHelper::$hookCalls[3], + Filesystem::signal_post_write, + '/foo.txt' + ); + } + public static function cancellingHook($params) { self::$hookCalls[] = array( 'signal' => Filesystem::signal_post_create, |