Skip to content

Commit 4d33494

Browse files
Erikvvicewind1991
authored andcommitted
AmazonS3: allow not implemented versioning
In case the S3 implementation does not implement versioning, set it to false. Versioning was introduced in Nexcloud in commit 09ffac5 This is needed for compatibility with the Storj gateway. Signed-off-by: Erik van Velzen <erik@evanv.nl>
1 parent 8ec5401 commit 4d33494

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

apps/files_external/lib/Lib/Storage/AmazonS3.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,7 @@ public function versioningEnabled(): bool {
732732
if ($this->versioningEnabled === null) {
733733
$cached = $this->memCache->get('versioning-enabled::' . $this->getBucket());
734734
if ($cached === null) {
735-
$result = $this->getConnection()->getBucketVersioning(['Bucket' => $this->getBucket()]);
736-
$this->versioningEnabled = $result->get('Status') === 'Enabled';
735+
$this->versioningEnabled = $this->getVersioningStatusFromBucket();
737736
$this->memCache->set('versioning-enabled::' . $this->getBucket(), $this->versioningEnabled, 60);
738737
} else {
739738
$this->versioningEnabled = $cached;
@@ -742,6 +741,19 @@ public function versioningEnabled(): bool {
742741
return $this->versioningEnabled;
743742
}
744743

744+
protected function getVersioningStatusFromBucket(): bool {
745+
try {
746+
$result = $this->getConnection()->getBucketVersioning(['Bucket' => $this->getBucket()]);
747+
return $result->get('Status') === 'Enabled';
748+
} catch (S3Exception $s3Exception) {
749+
// This is needed for compatibility with Storj gateway which does not support versioning yet
750+
if ($s3Exception->getAwsErrorCode() === 'NotImplemented') {
751+
return false;
752+
}
753+
throw $s3Exception;
754+
}
755+
}
756+
745757
public function hasUpdated($path, $time) {
746758
// for files we can get the proper mtime
747759
if ($path !== '' && $object = $this->headObject($path)) {

0 commit comments

Comments
 (0)