]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix cross storage move with shared storages
authorRobin Appelman <icewind@owncloud.com>
Mon, 13 Apr 2015 15:09:18 +0000 (17:09 +0200)
committerRobin Appelman <icewind@owncloud.com>
Mon, 13 Apr 2015 15:10:05 +0000 (17:10 +0200)
apps/files_sharing/lib/cache.php
apps/files_sharing/lib/sharedstorage.php
lib/private/files/cache/cache.php

index 2f982ec9dc6e0e536fbf88ac30009d800f6de016..49f5a4e8e7c07f5c69b9602b4746230e18232893 100644 (file)
@@ -235,18 +235,15 @@ class Shared_Cache extends Cache {
        }
 
        /**
-        * Move a file or folder in the cache
+        * Get the storage id and path needed for a move
         *
-        * @param string $source
-        * @param string $target
+        * @param string $path
+        * @return array [$storageId, $internalPath]
         */
-       public function move($source, $target) {
-               if ($cache = $this->getSourceCache($source)) {
-                       $file = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getItemType());
-                       if ($file && isset($file['path'])) {
-                               $cache->move($this->files[$source], $file['path']);
-                       }
-               }
+       protected function getMoveInfo($path) {
+               $cache = $this->getSourceCache($path);
+               $file = \OC_Share_Backend_File::getSource($path, $this->storage->getMountPoint(), $this->storage->getItemType());
+               return [$cache->getNumericStorageId(), $file['path']];
        }
 
        /**
index 6e3abb1f56cbb74dd4ed8fa10526be9f05e16680..c2253fcaa3c40097a267a6492d196073d497b149 100644 (file)
@@ -327,7 +327,10 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
                $targetFilename = basename($relPath2);
                list($user2, $path2) = \OCA\Files_Sharing\Helper::getUidAndFilename(dirname($relPath2));
                $rootView = new \OC\Files\View('');
-               return $rootView->rename('/' . $user1 . '/files/' . $path1, '/' . $user2 . '/files/' . $path2 . '/' . $targetFilename);
+               $rootView->getUpdater()->disable(); // dont update the cache here
+               $result = $rootView->rename('/' . $user1 . '/files/' . $path1, '/' . $user2 . '/files/' . $path2 . '/' . $targetFilename);
+               $rootView->getUpdater()->enable();
+               return $result;
        }
 
        public function copy($path1, $path2) {
index ee9da23109001a7a9e9361b8f31a1e350e26c76a..f00177d9c5bbe6ff8f7c35806b9cc58dd76ddd20 100644 (file)
@@ -438,6 +438,16 @@ class Cache {
                $this->moveFromCache($this, $source, $target);
        }
 
+       /**
+        * Get the storage id and path needed for a move
+        *
+        * @param string $path
+        * @return array [$storageId, $internalPath]
+        */
+       protected function getMoveInfo($path) {
+               return [$this->getNumericStorageId(), $path];
+       }
+
        /**
         * Move a file or folder in the cache
         *
@@ -455,10 +465,13 @@ class Cache {
                $sourceId = $sourceData['fileid'];
                $newParentId = $this->getParentId($targetPath);
 
+               list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath);
+               list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath);
+
                if ($sourceData['mimetype'] === 'httpd/unix-directory') {
                        //find all child entries
                        $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?';
-                       $result = \OC_DB::executeAudited($sql, [$sourceCache->getNumericStorageId(), $sourcePath . '/%']);
+                       $result = \OC_DB::executeAudited($sql, [$sourceStorageId, $sourcePath . '/%']);
                        $childEntries = $result->fetchAll();
                        $sourceLength = strlen($sourcePath);
                        \OC_DB::beginTransaction();
@@ -466,13 +479,13 @@ class Cache {
 
                        foreach ($childEntries as $child) {
                                $newTargetPath = $targetPath . substr($child['path'], $sourceLength);
-                               \OC_DB::executeAudited($query, [$this->getNumericStorageId(), $newTargetPath, md5($newTargetPath), $child['fileid']]);
+                               \OC_DB::executeAudited($query, [$targetStorageId, $newTargetPath, md5($newTargetPath), $child['fileid']]);
                        }
                        \OC_DB::commit();
                }
 
                $sql = 'UPDATE `*PREFIX*filecache` SET `storage` =  ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?';
-               \OC_DB::executeAudited($sql, [$this->getNumericStorageId(), $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]);
+               \OC_DB::executeAudited($sql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]);
        }
 
        /**