Skip to content

Commit

Permalink
feat: [Sftp] prevent Sftp Adapter from deleting directories when usin…
Browse files Browse the repository at this point in the history
…g delete
  • Loading branch information
tinect committed Dec 26, 2023
1 parent e897544 commit cbcde25
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/PhpseclibV3/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use League\Flysystem\UnableToCheckFileExistence;
use League\Flysystem\UnableToCopyFile;
use League\Flysystem\UnableToCreateDirectory;
use League\Flysystem\UnableToDeleteFile;
use League\Flysystem\UnableToMoveFile;
use League\Flysystem\UnableToReadFile;
use League\Flysystem\UnableToRetrieveMetadata;
Expand Down Expand Up @@ -176,9 +177,24 @@ public function readStream(string $path)

public function delete(string $path): void
{
if (empty($path)) {
throw UnableToDeleteFile::atLocation($path);
}

$fileExists = $this->fileExists($path);

if ($fileExists === false) {
if ($this->directoryExists($path)) {
throw UnableToDeleteFile::atLocation($path);
}

return;
}

$location = $this->prefixer->prefixPath($path);
$connection = $this->connectionProvider->provideConnection();
$connection->delete($location);

$connection->delete($location, false);
}

public function deleteDirectory(string $path): void
Expand Down

0 comments on commit cbcde25

Please sign in to comment.