]> source.dussan.org Git - nextcloud-server.git/commitdiff
Only update the filecache entry once the file has been written to S3 22514/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Mon, 31 Aug 2020 10:28:04 +0000 (12:28 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 31 Aug 2020 10:28:04 +0000 (12:28 +0200)
If we already update before we have no way to revert if the upload
fails.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
lib/private/Files/ObjectStore/ObjectStoreStorage.php

index b2ec094a71e14e388d35798255356b44a1f6b3d7..faa0342935e9a5118c3b9cf6ab4391d6a40a672e 100644 (file)
@@ -446,7 +446,13 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
 
                $exists = $this->getCache()->inCache($path);
                $uploadPath = $exists ? $path : $path . '.part';
-               $fileId = $this->getCache()->put($uploadPath, $stat);
+
+               if ($exists) {
+                       $fileId = $stat['fileid'];
+               } else {
+                       $fileId = $this->getCache()->put($uploadPath, $stat);
+               }
+
                $urn = $this->getURN($fileId);
                try {
                        //upload to object storage
@@ -461,6 +467,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
                                if (is_resource($countStream)) {
                                        fclose($countStream);
                                }
+                               $stat['size'] = $size;
                        } else {
                                $this->objectStore->writeObject($urn, $stream);
                        }
@@ -484,7 +491,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
                        throw $ex; // make this bubble up
                }
 
-               if (!$exists) {
+               if ($exists) {
+                       $this->getCache()->update($fileId, $stat);
+               } else {
                        if ($this->objectStore->objectExists($urn)) {
                                $this->getCache()->move($uploadPath, $path);
                        } else {