From 1d14bb94e971004083927019b6d0e28726eddfb3 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Thu, 13 Jan 2022 22:23:39 +0100 Subject: [PATCH] Convert exceptions --- src/AsyncAwsS3/AsyncAwsS3Adapter.php | 13 +++++++++---- .../GoogleCloudStorageAdapter.php | 14 ++++++++++++-- src/PhpseclibV2/SftpAdapter.php | 14 ++++++++++++-- src/PhpseclibV3/SftpAdapter.php | 14 ++++++++++++-- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/AsyncAwsS3/AsyncAwsS3Adapter.php b/src/AsyncAwsS3/AsyncAwsS3Adapter.php index a29ef4ad2..7737bdf1f 100644 --- a/src/AsyncAwsS3/AsyncAwsS3Adapter.php +++ b/src/AsyncAwsS3/AsyncAwsS3Adapter.php @@ -19,6 +19,7 @@ use League\Flysystem\FilesystemAdapter; use League\Flysystem\PathPrefixer; use League\Flysystem\StorageAttributes; +use League\Flysystem\UnableToCheckDirectoryExistence; use League\Flysystem\UnableToCheckFileExistence; use League\Flysystem\UnableToCopyFile; use League\Flysystem\UnableToDeleteFile; @@ -124,7 +125,7 @@ public function fileExists(string $path): bool ] )->isSuccess(); } catch (ClientException $e) { - throw UnableToCheckFileExistence::forLocation($path, $e); + throw UnableToCheckFileExistence:: forLocation($path, $e); } } @@ -258,10 +259,14 @@ public function fileSize(string $path): FileAttributes public function directoryExists(string $path): bool { - $prefix = $this->prefixer->prefixDirectoryPath($path); - $options = ['Bucket' => $this->bucket, 'Prefix' => $prefix, 'Delimiter' => '/']; + try { + $prefix = $this->prefixer->prefixDirectoryPath($path); + $options = ['Bucket' => $this->bucket, 'Prefix' => $prefix, 'Delimiter' => '/']; - return $this->client->listObjectsV2($options)->getKeyCount() > 0; + return $this->client->listObjectsV2($options)->getKeyCount() > 0; + } catch (Throwable $exception) { + throw UnableToCheckDirectoryExistence::forLocation($path, $exception); + } } public function listContents(string $path, bool $deep): iterable diff --git a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php index 272d843c2..764d6c293 100644 --- a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php +++ b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php @@ -14,6 +14,8 @@ use League\Flysystem\FilesystemException; use League\Flysystem\PathPrefixer; use League\Flysystem\StorageAttributes; +use League\Flysystem\UnableToCheckDirectoryExistence; +use League\Flysystem\UnableToCheckFileExistence; use League\Flysystem\UnableToCopyFile; use League\Flysystem\UnableToDeleteDirectory; use League\Flysystem\UnableToDeleteFile; @@ -59,14 +61,22 @@ public function fileExists(string $path): bool { $prefixedPath = $this->prefixer->prefixPath($path); - return $this->bucket->object($prefixedPath)->exists(); + try { + return $this->bucket->object($prefixedPath)->exists(); + } catch (Throwable $exception) { + UnableToCheckFileExistence::forLocation($path); + } } public function directoryExists(string $path): bool { $prefixedPath = $this->prefixer->prefixDirectoryPath($path); - return $this->bucket->object($prefixedPath)->exists(); + try { + return $this->bucket->object($prefixedPath)->exists(); + } catch (Throwable $exception) { + UnableToCheckDirectoryExistence::forLocation($path); + } } public function write(string $path, string $contents, Config $config): void diff --git a/src/PhpseclibV2/SftpAdapter.php b/src/PhpseclibV2/SftpAdapter.php index c595f513f..aa2cf8049 100644 --- a/src/PhpseclibV2/SftpAdapter.php +++ b/src/PhpseclibV2/SftpAdapter.php @@ -11,6 +11,8 @@ use League\Flysystem\FilesystemException; use League\Flysystem\PathPrefixer; use League\Flysystem\StorageAttributes; +use League\Flysystem\UnableToCheckDirectoryExistence; +use League\Flysystem\UnableToCheckFileExistence; use League\Flysystem\UnableToCopyFile; use League\Flysystem\UnableToCreateDirectory; use League\Flysystem\UnableToMoveFile; @@ -63,14 +65,22 @@ public function fileExists(string $path): bool { $location = $this->prefixer->prefixPath($path); - return $this->connectionProvider->provideConnection()->is_file($location); + try { + return $this->connectionProvider->provideConnection()->is_file($location); + } catch (Throwable $exception) { + throw UnableToCheckFileExistence::forLocation($path, $exception); + } } public function directoryExists(string $path): bool { $location = $this->prefixer->prefixDirectoryPath($path); - return $this->connectionProvider->provideConnection()->is_dir($location); + try { + return $this->connectionProvider->provideConnection()->is_dir($location); + } catch (Throwable $exception) { + throw UnableToCheckDirectoryExistence::forLocation($path, $exception); + } } /** diff --git a/src/PhpseclibV3/SftpAdapter.php b/src/PhpseclibV3/SftpAdapter.php index 2cc94523f..e48cbaf07 100644 --- a/src/PhpseclibV3/SftpAdapter.php +++ b/src/PhpseclibV3/SftpAdapter.php @@ -11,6 +11,8 @@ use League\Flysystem\FilesystemException; use League\Flysystem\PathPrefixer; use League\Flysystem\StorageAttributes; +use League\Flysystem\UnableToCheckDirectoryExistence; +use League\Flysystem\UnableToCheckFileExistence; use League\Flysystem\UnableToCopyFile; use League\Flysystem\UnableToCreateDirectory; use League\Flysystem\UnableToMoveFile; @@ -63,14 +65,22 @@ public function fileExists(string $path): bool { $location = $this->prefixer->prefixPath($path); - return $this->connectionProvider->provideConnection()->is_file($location); + try { + return $this->connectionProvider->provideConnection()->is_file($location); + } catch (Throwable $exception) { + throw UnableToCheckFileExistence::forLocation($path, $exception); + } } public function directoryExists(string $path): bool { $location = $this->prefixer->prefixDirectoryPath($path); - return $this->connectionProvider->provideConnection()->is_dir($location); + try { + return $this->connectionProvider->provideConnection()->is_dir($location); + } catch (Throwable $exception) { + throw UnableToCheckDirectoryExistence::forLocation($path, $exception); + } } /**