diff options
author | C. Montero Luque <cmonteroluque@users.noreply.github.com> | 2016-03-01 14:42:59 -0500 |
---|---|---|
committer | C. Montero Luque <cmonteroluque@users.noreply.github.com> | 2016-03-01 14:42:59 -0500 |
commit | 069c65479d9ad0587415757c5bab200b6f00127e (patch) | |
tree | 9607ba50e4d2f84f7e4df0d91c02f563dde2141e | |
parent | 745fdc48007d5d2f29c62266627731bd0ea0aa3d (diff) | |
parent | 5a2fe4107c03126b4b635c48998eb196780642f1 (diff) | |
download | nextcloud-server-069c65479d9ad0587415757c5bab200b6f00127e.tar.gz nextcloud-server-069c65479d9ad0587415757c5bab200b6f00127e.zip |
Merge pull request #22684 from owncloud/part-file-root
allow putting the part file in the view root
-rw-r--r-- | apps/dav/lib/connector/sabre/file.php | 17 | ||||
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/requesttest/partfileinrootupload.php | 56 | ||||
-rw-r--r-- | config/config.sample.php | 8 |
3 files changed, 77 insertions, 4 deletions
diff --git a/apps/dav/lib/connector/sabre/file.php b/apps/dav/lib/connector/sabre/file.php index 9c8344bc5db..7aa1693581e 100644 --- a/apps/dav/lib/connector/sabre/file.php +++ b/apps/dav/lib/connector/sabre/file.php @@ -112,7 +112,7 @@ class File extends Node implements IFile { if ($needsPartFile) { // mark file as partial while uploading (ignored by the scanner) - $partFilePath = $this->path . '.ocTransferId' . rand() . '.part'; + $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; } else { // upload file directly as the final path $partFilePath = $this->path; @@ -133,12 +133,12 @@ class File extends Node implements IFile { list($count, $result) = \OC_Helper::streamCopy($data, $target); fclose($target); - if($result === false) { + if ($result === false) { $expected = -1; if (isset($_SERVER['CONTENT_LENGTH'])) { $expected = $_SERVER['CONTENT_LENGTH']; } - throw new Exception('Error while copying file to target location (copied bytes: ' . $count . ', expected filesize: '. $expected .' )'); + throw new Exception('Error while copying file to target location (copied bytes: ' . $count . ', expected filesize: ' . $expected . ' )'); } // if content length is sent by client: @@ -233,6 +233,15 @@ class File extends Node implements IFile { return '"' . $this->info->getEtag() . '"'; } + private function getPartFileBasePath($path) { + $partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true); + if ($partFileInStorage) { + return $path; + } else { + return md5($path); // will place it in the root of the view with a unique name + } + } + /** * @param string $path */ @@ -420,7 +429,7 @@ class File extends Node implements IFile { if ($needsPartFile) { // we first assembly the target file as a part file - $partFile = $path . '/' . $info['name'] . '.ocTransferId' . $info['transferid'] . '.part'; + $partFile = $this->getPartFileBasePath($path . '/' . $info['name']) . '.ocTransferId' . $info['transferid'] . '.part'; /** @var \OC\Files\Storage\Storage $targetStorage */ list($partStorage, $partInternalPath) = $this->fileView->resolvePath($partFile); diff --git a/apps/dav/tests/unit/connector/sabre/requesttest/partfileinrootupload.php b/apps/dav/tests/unit/connector/sabre/requesttest/partfileinrootupload.php new file mode 100644 index 00000000000..52790c5b00b --- /dev/null +++ b/apps/dav/tests/unit/connector/sabre/requesttest/partfileinrootupload.php @@ -0,0 +1,56 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\DAV\Tests\Unit\Connector\Sabre\RequestTest; + +use OC\Files\View; +use Test\Traits\EncryptionTrait; + +/** + * Class EncryptionUploadTest + * + * @group DB + * + * @package OCA\DAV\Tests\Unit\Connector\Sabre\RequestTest + */ +class PartFileInRootUpload extends UploadTest { + protected function setUp() { + $config = \OC::$server->getConfig(); + $mockConfig = $this->getMock('\OCP\IConfig'); + $mockConfig->expects($this->any()) + ->method('getSystemValue') + ->will($this->returnCallback(function ($key, $default) use ($config) { + if ($key === 'part_file_in_storage') { + return false; + } else { + return $config->getSystemValue($key, $default); + } + })); + $this->overwriteService('AllConfig', $mockConfig); + parent::setUp(); + } + + protected function tearDown() { + $this->restoreService('AllConfig'); + return parent::tearDown(); + } +} diff --git a/config/config.sample.php b/config/config.sample.php index 81a02efb3f7..1a6c8b31280 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -1104,6 +1104,14 @@ $CONFIG = array( 'filesystem_check_changes' => 0, /** + * On default ownCloud will store the part files created during upload in the + * same storage as the upload target. Setting this to false will store the part + * files in the root of the users folder which might be required to work with certain + * external storage setups that have limited rename capabilities. + */ +'part_file_in_storage' => true, + +/** * All css and js files will be served by the Web server statically in one js * file and one css file if this is set to ``true``. This improves performance. */ |