summaryrefslogtreecommitdiffstats
path: root/apps/files_versions/lib/versions.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions/lib/versions.php')
-rw-r--r--apps/files_versions/lib/versions.php46
1 files changed, 40 insertions, 6 deletions
diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php
index bdb26896948..82e0ecc3e2f 100644
--- a/apps/files_versions/lib/versions.php
+++ b/apps/files_versions/lib/versions.php
@@ -24,6 +24,8 @@ class Storage {
// files for which we can remove the versions after the delete operation was successful
private static $deletedFiles = array();
+ private static $sourcePathAndUser = array();
+
private static $max_versions_per_interval = array(
//first 10sec, one version every 2sec
1 => array('intervalEndsAfter' => 10, 'step' => 2),
@@ -51,6 +53,34 @@ class Storage {
}
/**
+ * Remember the owner and the owner path of the source file
+ *
+ * @param string $source source path
+ */
+ public static function setSourcePathAndUser($source) {
+ list($uid, $path) = self::getUidAndFilename($source);
+ self::$sourcePathAndUser[$source] = array('uid' => $uid, 'path' => $path);
+ }
+
+ /**
+ * Gets the owner and the owner path from the source path
+ *
+ * @param string $source source path
+ * @return array with user id and path
+ */
+ public static function getSourcePathAndUser($source) {
+
+ if (isset(self::$sourcePathAndUser[$source])) {
+ $uid = self::$sourcePathAndUser[$source]['uid'];
+ $path = self::$sourcePathAndUser[$source]['path'];
+ unset(self::$sourcePathAndUser[$source]);
+ } else {
+ $uid = $path = false;
+ }
+ return array($uid, $path);
+ }
+
+ /**
* get current size of all versions from a given user
*
* @param string $user user who owns the versions
@@ -180,16 +210,20 @@ class Storage {
* @param string $operation can be 'copy' or 'rename'
*/
public static function renameOrCopy($old_path, $new_path, $operation) {
- list($uid, $oldpath) = self::getUidAndFilename($old_path);
+ list($uid, $oldpath) = self::getSourcePathAndUser($old_path);
+
+ // it was a upload of a existing file if no old path exists
+ // in this case the pre-hook already called the store method and we can
+ // stop here
+ if ($oldpath === false) {
+ return true;
+ }
+
list($uidn, $newpath) = self::getUidAndFilename($new_path);
$versions_view = new \OC\Files\View('/'.$uid .'/files_versions');
$files_view = new \OC\Files\View('/'.$uid .'/files');
- // if the file already exists than it was a upload of a existing file
- // over the web interface -> store() is the right function we need here
- if ($files_view->file_exists($newpath)) {
- return self::store($new_path);
- }
+
if ( $files_view->is_dir($oldpath) && $versions_view->is_dir($oldpath) ) {
$versions_view->$operation($oldpath, $newpath);