diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-08-31 21:44:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-31 21:44:19 +0200 |
commit | c83bd2a7fdf19d2f62f7c4162703d05e2a906d6c (patch) | |
tree | 7a6043f8fde639fae4b4d72d4b8c7733dda83f46 | |
parent | 4ef423913dbfb514d17b54bab69460427d88799a (diff) | |
parent | 952ec3370e2f096f9489863edc8c48842e3fd8af (diff) | |
download | nextcloud-server-c83bd2a7fdf19d2f62f7c4162703d05e2a906d6c.tar.gz nextcloud-server-c83bd2a7fdf19d2f62f7c4162703d05e2a906d6c.zip |
Merge pull request #22521 from nextcloud/backport/22514/stable19
[stable19] Fix S3 error handling
-rw-r--r-- | lib/private/Files/ObjectStore/ObjectStoreStorage.php | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index a5112bcbba6..faa0342935e 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -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,19 +467,33 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common { if (is_resource($countStream)) { fclose($countStream); } + $stat['size'] = $size; } else { $this->objectStore->writeObject($urn, $stream); } } catch (\Exception $ex) { - $this->getCache()->remove($uploadPath); - $this->logger->logException($ex, [ - 'app' => 'objectstore', - 'message' => 'Could not create object ' . $urn . ' for ' . $path, - ]); + if (!$exists) { + /* + * Only remove the entry if we are dealing with a new file. + * Else people lose access to existing files + */ + $this->getCache()->remove($uploadPath); + $this->logger->logException($ex, [ + 'app' => 'objectstore', + 'message' => 'Could not create object ' . $urn . ' for ' . $path, + ]); + } else { + $this->logger->logException($ex, [ + 'app' => 'objectstore', + 'message' => 'Could not update object ' . $urn . ' for ' . $path, + ]); + } 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 { |