]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix moving files from external storage to object store trashbin
authorRobin Appelman <robin@icewind.nl>
Mon, 29 Jun 2020 16:14:47 +0000 (18:14 +0200)
committerRobin Appelman <robin@icewind.nl>
Fri, 31 Jul 2020 15:32:05 +0000 (17:32 +0200)
having the "cache rename" after the "storage move" caused the target
to get the fileid from the source file, without taking care that the object
is stored under the original file id.

By doing the "cache rename" first, we trigger the "update existing file"
logic while moving the file to the object store and the object gets stored for the
correct file id

Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_trashbin/lib/Trashbin.php
lib/private/Files/Storage/Common.php

index 972afe40dcdc5c20f448e50c0cc3ee3bae3379ee..2647cb2f0f850ea438db97f9e3beb327363d18da 100644 (file)
@@ -278,6 +278,8 @@ class Trashbin {
                /** @var \OC\Files\Storage\Storage $sourceStorage */
                [$sourceStorage, $sourceInternalPath] = $ownerView->resolvePath('/files/' . $ownerPath);
 
+               $trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
+
                try {
                        $moveSuccessful = true;
                        if ($trashStorage->file_exists($trashInternalPath)) {
@@ -301,8 +303,6 @@ class Trashbin {
                        return false;
                }
 
-               $trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
-
                if ($moveSuccessful) {
                        $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
                        $result = $query->execute(array($filename, $timestamp, $location, $owner));
index 82ac49b9fdfb3fba8f1d196f02ea714099023847..10941937a55138fc603e1a3616084090e8044ad1 100644 (file)
@@ -618,18 +618,15 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
                        }
                } else {
                        $source = $sourceStorage->fopen($sourceInternalPath, 'r');
-                       // TODO: call fopen in a way that we execute again all storage wrappers
-                       // to avoid that we bypass storage wrappers which perform important actions
-                       // for this operation. Same is true for all other operations which
-                       // are not the same as the original one.Once this is fixed we also
-                       // need to adjust the encryption wrapper.
-                       $target = $this->fopen($targetInternalPath, 'w');
-                       list(, $result) = \OC_Helper::streamCopy($source, $target);
+                       if ($source) {
+                               $result = $this->writeStream($targetInternalPath, $source) > 0;
+                       } else {
+                               $result = false;
+                       }
+
                        if ($result and $preserveMtime) {
                                $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
                        }
-                       fclose($source);
-                       fclose($target);
 
                        if (!$result) {
                                // delete partially written target file