Skip to content

Commit b1ffafc

Browse files
authored
Merge pull request #49496 from nextcloud/backport/49494/stable29
[stable29] fix: throw correct exception type when we can't verify if an s3 bucket exists
2 parents a0ae640 + e71880d commit b1ffafc

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ jobs:
5151
repository: nextcloud/user_saml
5252
path: apps/user_saml
5353

54+
- name: Install user_saml
55+
run: |
56+
cd apps/user_saml
57+
composer i
58+
cd ../..
59+
5460
- name: Pull images
5561
run: |
5662
docker pull ghcr.io/icewind1991/samba-krb-test-dc

lib/private/Files/ObjectStore/S3ConnectionTrait.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use Aws\S3\S3Client;
4141
use GuzzleHttp\Promise;
4242
use GuzzleHttp\Promise\RejectedPromise;
43+
use OCP\Files\StorageNotAvailableException;
4344
use OCP\ICertificateManager;
4445
use OCP\Server;
4546
use Psr\Log\LoggerInterface;
@@ -155,12 +156,12 @@ public function getConnection() {
155156
$logger->debug('Bucket "' . $this->bucket . '" This bucket name is not dns compatible, it may contain invalid characters.',
156157
['app' => 'objectstore']);
157158
}
158-
159+
159160
if ($this->params['verify_bucket_exists'] && !$this->connection->doesBucketExist($this->bucket)) {
160161
try {
161162
$logger->info('Bucket "' . $this->bucket . '" does not exist - creating it.', ['app' => 'objectstore']);
162163
if (!$this->connection::isBucketDnsCompatible($this->bucket)) {
163-
throw new \Exception("The bucket will not be created because the name is not dns compatible, please correct it: " . $this->bucket);
164+
throw new StorageNotAvailableException("The bucket will not be created because the name is not dns compatible, please correct it: " . $this->bucket);
164165
}
165166
$this->connection->createBucket(['Bucket' => $this->bucket]);
166167
$this->testTimeout();
@@ -170,17 +171,17 @@ public function getConnection() {
170171
'app' => 'objectstore',
171172
]);
172173
if ($e->getAwsErrorCode() !== 'BucketAlreadyOwnedByYou') {
173-
throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
174+
throw new StorageNotAvailableException('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
174175
}
175176
}
176177
}
177-
178+
178179
// google cloud's s3 compatibility doesn't like the EncodingType parameter
179180
if (strpos($base_url, 'storage.googleapis.com')) {
180181
$this->connection->getHandlerList()->remove('s3.auto_encode');
181182
}
182183
} catch (S3Exception $e) {
183-
throw new \Exception('S3 service is unable to handle request: ' . $e->getMessage());
184+
throw new StorageNotAvailableException('S3 service is unable to handle request: ' . $e->getMessage());
184185
}
185186

186187
return $this->connection;

lib/private/Files/SetupManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
use OC_App;
4040
use OC_Hook;
4141
use OC_Util;
42-
use OCA\Files_External\Config\ConfigAdapter;
42+
use OCA\Files_External\Config\ExternalMountPoint;
4343
use OCA\Files_Sharing\External\Mount;
4444
use OCA\Files_Sharing\ISharedMountPoint;
4545
use OCA\Files_Sharing\SharedMount;
@@ -149,7 +149,7 @@ function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEna
149149

150150
// install storage availability wrapper, before most other wrappers
151151
Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
152-
$externalMount = $mount instanceof ConfigAdapter || $mount instanceof Mount;
152+
$externalMount = $mount instanceof ExternalMountPoint || $mount instanceof Mount;
153153
if ($externalMount && !$storage->isLocal()) {
154154
return new Availability(['storage' => $storage]);
155155
}

0 commit comments

Comments
 (0)