summaryrefslogtreecommitdiffstats
path: root/apps/files_versions/lib/storage.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions/lib/storage.php')
-rw-r--r--apps/files_versions/lib/storage.php32
1 files changed, 28 insertions, 4 deletions
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php
index 5879cb01641..45f96ee776b 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/storage.php
@@ -282,11 +282,16 @@ class Storage {
}
/**
- * rollback to an old version of a file.
+ * Rollback to an old version of a file.
+ *
+ * @param string $file file name
+ * @param int $revision revision timestamp
*/
public static function rollback($file, $revision) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+ // add expected leading slash
+ $file = '/' . ltrim($file, '/');
list($uid, $filename) = self::getUidAndFilename($file);
$users_view = new \OC\Files\View('/'.$uid);
$files_view = new \OC\Files\View('/'.\OCP\User::getUser().'/files');
@@ -302,12 +307,11 @@ class Storage {
}
// 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);
}
}
@@ -315,6 +319,23 @@ class Storage {
}
+ /**
+ * 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) {
+ list($storage1, $internalPath1) = $view->resolvePath($path1);
+ list($storage2, $internalPath2) = $view->resolvePath($path2);
+
+ $result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
+
+ return ($result !== false);
+ }
/**
* get a list of all available versions of a file in descending chronological order
@@ -325,6 +346,9 @@ class Storage {
*/
public static function getVersions($uid, $filename, $userFullPath = '') {
$versions = array();
+ if ($filename === '') {
+ return $versions;
+ }
// fetch for old versions
$view = new \OC\Files\View('/' . $uid . '/');