Skip to content

Commit

Permalink
feat: [ZipArchive] prevent ZipArchive Adapter from deleting directori…
Browse files Browse the repository at this point in the history
…es when using delete
  • Loading branch information
tinect committed Dec 27, 2023
1 parent ccf54b9 commit 2c26cf9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/ZipArchive/ZipArchiveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ public function readStream(string $path)

public function delete(string $path): void
{
if (empty($path) || \str_ends_with($path, '/')) {
throw UnableToDeleteFile::atLocation($path);
}

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

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

return;
}

$prefixedPath = $this->pathPrefixer->prefixPath($path);
$zipArchive = $this->zipArchiveProvider->createZipArchive();
$success = $zipArchive->locateName($prefixedPath) === false || $zipArchive->deleteName($prefixedPath);
Expand All @@ -155,7 +169,7 @@ public function deleteDirectory(string $path): void

$itemPath = $stats['name'];

if (strpos($itemPath, $prefixedPath) !== 0) {
if (!str_starts_with($itemPath, $prefixedPath)) {
continue;
}

Expand Down

0 comments on commit 2c26cf9

Please sign in to comment.