Skip to content

Commit 01b2ae4

Browse files
authored
Merge pull request #49494 from nextcloud/s3-bucket-create-exception
fix: throw correct exception type when we can't verify if an s3 bucket exists
2 parents 14f7e56 + eb05cc2 commit 01b2ae4

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

.github/workflows/files-external-smb-kerberos.yml

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ jobs:
5353
repository: nextcloud/user_saml
5454
path: apps/user_saml
5555

56+
- name: Install user_saml
57+
run: |
58+
cd apps/user_saml
59+
composer i
60+
cd ../..
61+
5662
- name: Pull images
5763
run: |
5864
docker pull ghcr.io/icewind1991/samba-krb-test-dc

lib/private/Files/ObjectStore/S3ConnectionTrait.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Aws\S3\S3Client;
1414
use GuzzleHttp\Promise\Create;
1515
use GuzzleHttp\Promise\RejectedPromise;
16+
use OCP\Files\StorageNotAvailableException;
1617
use OCP\ICertificateManager;
1718
use OCP\Server;
1819
use Psr\Log\LoggerInterface;
@@ -132,7 +133,7 @@ public function getConnection() {
132133
try {
133134
$logger->info('Bucket "' . $this->bucket . '" does not exist - creating it.', ['app' => 'objectstore']);
134135
if (!$this->connection::isBucketDnsCompatible($this->bucket)) {
135-
throw new \Exception('The bucket will not be created because the name is not dns compatible, please correct it: ' . $this->bucket);
136+
throw new StorageNotAvailableException('The bucket will not be created because the name is not dns compatible, please correct it: ' . $this->bucket);
136137
}
137138
$this->connection->createBucket(['Bucket' => $this->bucket]);
138139
$this->testTimeout();
@@ -142,17 +143,17 @@ public function getConnection() {
142143
'app' => 'objectstore',
143144
]);
144145
if ($e->getAwsErrorCode() !== 'BucketAlreadyOwnedByYou') {
145-
throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
146+
throw new StorageNotAvailableException('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
146147
}
147148
}
148149
}
149-
150+
150151
// google cloud's s3 compatibility doesn't like the EncodingType parameter
151152
if (strpos($base_url, 'storage.googleapis.com')) {
152153
$this->connection->getHandlerList()->remove('s3.auto_encode');
153154
}
154155
} catch (S3Exception $e) {
155-
throw new \Exception('S3 service is unable to handle request: ' . $e->getMessage());
156+
throw new StorageNotAvailableException('S3 service is unable to handle request: ' . $e->getMessage());
156157
}
157158

158159
return $this->connection;

lib/private/Files/SetupManager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use OC_App;
2525
use OC_Hook;
2626
use OC_Util;
27-
use OCA\Files_External\Config\ConfigAdapter;
27+
use OCA\Files_External\Config\ExternalMountPoint;
2828
use OCA\Files_Sharing\External\Mount;
2929
use OCA\Files_Sharing\ISharedMountPoint;
3030
use OCA\Files_Sharing\SharedMount;
@@ -135,7 +135,7 @@ function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEna
135135

136136
// install storage availability wrapper, before most other wrappers
137137
Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
138-
$externalMount = $mount instanceof ConfigAdapter || $mount instanceof Mount;
138+
$externalMount = $mount instanceof ExternalMountPoint || $mount instanceof Mount;
139139
if ($externalMount && !$storage->isLocal()) {
140140
return new Availability(['storage' => $storage]);
141141
}

0 commit comments

Comments
 (0)