diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2015-10-19 17:18:57 +0200 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2015-10-19 17:18:57 +0200 |
commit | 2895c912910a5a24ce6fae5d487ff8136c7a5042 (patch) | |
tree | d661a84df7c55b4260d9efce06882f8b98364ca9 /apps/files_versions | |
parent | c530c9c322d9475fbbeccce834ba06083d7ae36a (diff) | |
parent | de55f6afbf1eb4bf858ff61e07c6fa475269bea1 (diff) | |
download | nextcloud-server-2895c912910a5a24ce6fae5d487ff8136c7a5042.tar.gz nextcloud-server-2895c912910a5a24ce6fae5d487ff8136c7a5042.zip |
Merge pull request #17641 from owncloud/fix_objectstore_rename
don't move files in cache twice, fixes renaming for objectstores
Diffstat (limited to 'apps/files_versions')
-rw-r--r-- | apps/files_versions/lib/storage.php | 35 | ||||
-rw-r--r-- | apps/files_versions/tests/versions.php | 5 |
2 files changed, 28 insertions, 12 deletions
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php index fd51a54b108..dd8af1b8d18 100644 --- a/apps/files_versions/lib/storage.php +++ b/apps/files_versions/lib/storage.php @@ -347,7 +347,20 @@ class Storage { $view->lockFile($path1, ILockingProvider::LOCK_EXCLUSIVE); $view->lockFile($path2, ILockingProvider::LOCK_EXCLUSIVE); - $result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2); + // TODO add a proper way of overwriting a file while maintaining file ids + if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) { + $source = $storage1->fopen($internalPath1, 'r'); + $target = $storage2->fopen($internalPath2, 'w'); + list(, $result) = \OC_Helper::streamCopy($source, $target); + fclose($source); + fclose($target); + + if ($result !== false) { + $storage1->unlink($internalPath1); + } + } else { + $result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2); + } $view->unlockFile($path1, ILockingProvider::LOCK_EXCLUSIVE); $view->unlockFile($path2, ILockingProvider::LOCK_EXCLUSIVE); @@ -663,17 +676,21 @@ class Storage { // calculate available space for version history // subtract size of files and current versions size from quota - if ($softQuota) { - $files_view = new \OC\Files\View('/'.$uid.'/files'); - $rootInfo = $files_view->getFileInfo('/', false); - $free = $quota-$rootInfo['size']; // remaining free space for user - if ( $free > 0 ) { - $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - ($versionsSize + $offset); // how much space can be used for versions + if ($quota >= 0) { + if ($softQuota) { + $files_view = new \OC\Files\View('/' . $uid . '/files'); + $rootInfo = $files_view->getFileInfo('/', false); + $free = $quota - $rootInfo['size']; // remaining free space for user + if ($free > 0) { + $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - ($versionsSize + $offset); // how much space can be used for versions + } else { + $availableSpace = $free - $versionsSize - $offset; + } } else { - $availableSpace = $free - $versionsSize - $offset; + $availableSpace = $quota - $offset; } } else { - $availableSpace = $quota - $offset; + $availableSpace = PHP_INT_MAX; } $allVersions = Storage::getVersions($uid, $filename); diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php index 00d2b75b7a9..2979de2ac98 100644 --- a/apps/files_versions/tests/versions.php +++ b/apps/files_versions/tests/versions.php @@ -301,11 +301,10 @@ class Test_Files_Versioning extends \Test\TestCase { // execute rename hook of versions app \OC\Files\Filesystem::rename('/folder1/test.txt', '/folder1/folder2/test.txt'); - - self::loginHelper(self::TEST_VERSIONS_USER2); - $this->runCommands(); + self::loginHelper(self::TEST_VERSIONS_USER); + $this->assertFalse($this->rootView->file_exists($v1)); $this->assertFalse($this->rootView->file_exists($v2)); |