Skip to content

Commit

Permalink
Merge pull request #22523 from nextcloud/backport/22514/stable17
Browse files Browse the repository at this point in the history
[stable17] Fix S3 error handling
  • Loading branch information
rullzer committed Aug 31, 2020
2 parents 59a6147 + 0eeb1ea commit e7761b6
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,13 @@ public function writeStream(string $path, $stream, int $size = null): int {

$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
Expand All @@ -456,19 +462,33 @@ public function writeStream(string $path, $stream, int $size = null): int {
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 {
Expand Down

0 comments on commit e7761b6

Please sign in to comment.