Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable18] Fix S3 error handling #22522

Merged
merged 2 commits into from
Aug 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,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 @@ -459,19 +465,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