Skip to content

Commit

Permalink
Always stream copy when restoring version
Browse files Browse the repository at this point in the history
This is a workaround to make it possible to keep the file id when
restoring a file. Please note that a stream copy would happen anyway
when restoring cross-storage.
  • Loading branch information
Vincent Petry committed Apr 8, 2015
1 parent f7329cb commit b0af09f
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions apps/files_versions/lib/storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,38 @@ public static function rollback($file, $revision) {
}

// rollback
if( @$users_view->rename('files_versions'.$filename.'.v'.$revision, 'files'.$filename) ) {
if (self::copyFileContents($users_view, 'files_versions' . $filename . '.v' . $revision, 'files' . $filename)) {
$files_view->touch($file, $revision);
Storage::scheduleExpire($file);
return true;

}else if ( $versionCreated ) {
} else if ($versionCreated) {
self::deleteVersion($users_view, $version);
}
}
return false;

}

/**
* Stream copy file contents from $path1 to $path2
*
* @param \OC\Files\View $view view to use for copying
* @param string $path1 source file to copy
* @param string $path2 target file
*
* @return bool true for success, false otherwise
*/
private static function copyFileContents($view, $path1, $path2) {
$source = $view->fopen($path1, 'r');
$target = $view->fopen($path2, 'w');
// FIXME: might need to use part file to avoid concurrent writes
// (this would be an issue anyway when renaming/restoring cross-storage)
list(, $result) = \OC_Helper::streamCopy($source, $target);
fclose($source);
fclose($target);

return ($result !== false);
}

/**
* get a list of all available versions of a file in descending chronological order
Expand Down

0 comments on commit b0af09f

Please sign in to comment.