summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-08-31 19:03:24 +0200
committerGitHub <noreply@github.com>2020-08-31 19:03:24 +0200
commit8dd249937f1252586a7e4674caf3c9b96bf835de (patch)
tree175939b3a82be9b5a1d4697f964085f78150c17d
parent6b835e3c1dd0a00a8264a7702abe001717b86d6d (diff)
parent789b33aba498dddb7c73a9966da75c82008d42de (diff)
downloadnextcloud-server-8dd249937f1252586a7e4674caf3c9b96bf835de.tar.gz
nextcloud-server-8dd249937f1252586a7e4674caf3c9b96bf835de.zip
Merge pull request #22514 from nextcloud/fix/s3/only_delete_new_failed
Fix S3 error handling
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreStorage.php34
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 {