Fix preserving file ids when restoring a file with object storage

This commit is contained in:
Robin Appelman 2015-10-13 16:15:00 +02:00 committed by Thomas Müller
parent 0c6c36d0c5
commit 54cea05271
1 changed files with 14 additions and 1 deletions

View File

@ -347,7 +347,20 @@ class Storage {
$view->lockFile($path1, ILockingProvider::LOCK_EXCLUSIVE); $view->lockFile($path1, ILockingProvider::LOCK_EXCLUSIVE);
$view->lockFile($path2, ILockingProvider::LOCK_EXCLUSIVE); $view->lockFile($path2, ILockingProvider::LOCK_EXCLUSIVE);
// 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); $result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
}
$view->unlockFile($path1, ILockingProvider::LOCK_EXCLUSIVE); $view->unlockFile($path1, ILockingProvider::LOCK_EXCLUSIVE);
$view->unlockFile($path2, ILockingProvider::LOCK_EXCLUSIVE); $view->unlockFile($path2, ILockingProvider::LOCK_EXCLUSIVE);