From 7d3b5956e400cc948ed23144b54fe1e3c53ce094 Mon Sep 17 00:00:00 2001 From: "Bernd.Rederlechner@t-systems.com" Date: Tue, 11 May 2021 16:09:54 +0000 Subject: [PATCH] Change fragment handling strategy for empty files Signed-off-by: Bernd.Rederlechner@t-systems.com --- .../Files/ObjectStore/S3ObjectTrait.php | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index 549120bc2c..8df61ab7cf 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -97,40 +97,36 @@ trait S3ObjectTrait { $count += $read; }); + $s3params = [ + 'bucket' => $this->bucket, + 'key' => $urn, + 'part_size' => $this->uploadPartSize, + 'params' => [ + 'ContentType' => $mimetype + ] + $this->getSseKmsPutParameters(), + ]; - if ($count === 0 && feof($countStream)) { - // This is an empty file so just touch it then - $s3params = [ - 'params' => $this->getSseKmsPutParameters(), - ]; - $uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, '', 'private', $s3params); - } else { - $s3params = [ - 'bucket' => $this->bucket, - 'key' => $urn, - 'part_size' => $this->uploadPartSize, - 'params' => [ - 'ContentType' => $mimetype - ] + $this->getSseKmsPutParameters(), - ]; - - // maybe, we should also use ObjectUploader here in the future - // it does direct uploads for small files < 5MB and multipart otherwise - // $uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, $countStream, 'private', $s3params); - $uploader = new MultipartUploader($this->getConnection(), $countStream, $s3params); - } + // maybe, we should also use ObjectUploader here in the future + // it does direct uploads for small files < 5MB and multipart otherwise + // $uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, $countStream, 'private', $s3params); + $uploader = new MultipartUploader($this->getConnection(), $countStream, $s3params); try { $uploader->upload(); } catch (S3MultipartUploadException $e) { // if anything goes wrong with multipart, make sure that you donĀ“t poison s3 bucket with fragments - $this->getConnection()->abortMultipartUpload([ - 'Bucket' => $this->bucket, - 'Key' => $urn, - 'UploadId' => $uploader->getState()->getId() - ]); - - throw $e; + $this->getConnection()->abortMultipartUpload($uploader->getState()->getId()); + + if ($count === 0 && feof($countStream)) { + // This is an empty file case, so just touch it + $s3params = [ + 'params' => $this->getSseKmsPutParameters(), + ]; + $uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, '', 'private', $s3params); + $uploader->upload(); + } else { + throw $e; + } } finally { // this handles [S3] fclose(): supplied resource is not a valid stream resource #23373 // see https://stackoverflow.com/questions/11247507/fclose-18-is-not-a-valid-stream-resource/11247555