Skip to content

Commit c8e1143

Browse files
authored
Merge pull request #31946 from nextcloud/s3-versioning-not-implemented-23
[23] AmazonS3: allow not implemented versioning
2 parents 0444c15 + 4d33494 commit c8e1143

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)