Skip to content

Commit

Permalink
Convert exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Jan 13, 2022
1 parent 4d70f2d commit 1d14bb9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/AsyncAwsS3/AsyncAwsS3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,7 +125,7 @@ public function fileExists(string $path): bool
]
)->isSuccess();
} catch (ClientException $e) {
throw UnableToCheckFileExistence::forLocation($path, $e);
throw UnableToCheckFileExistence:: forLocation($path, $e);

This comment has been minimized.

Copy link
@Art4

Art4 Jan 14, 2022

Contributor

Was this change intentional?

This comment has been minimized.

Copy link
@frankdejonge

frankdejonge Jan 14, 2022

Author Member

ah, no it wasn't

}
}

Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/GoogleCloudStorage/GoogleCloudStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/PhpseclibV2/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/PhpseclibV3/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit 1d14bb9

Please sign in to comment.