Skip to content

Commit

Permalink
Check that file exists before deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Dec 3, 2024
1 parent 219826d commit 8676256
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed

- More deployer settings are now redacted when generating a diagnostics report.
- The existence of cached files is checked before deletion, to prevent unnecessarily logged warnings ([#741](https://github.com/putyourlightson/craft-blitz/issues/741)).

## 5.9.6 - 2024-11-15

Expand Down
14 changes: 12 additions & 2 deletions src/drivers/storage/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,17 @@ private function saveToFile(string $filePath, string $value): void
*/
private function delete(string $filePath): void
{
FileHelper::unlink($filePath);
FileHelper::unlink($filePath . '.gz');
$this->deleteIfExists($filePath);
$this->deleteIfExists($filePath . '.gz');
}

/**
* Deletes a file if it exists.
*/
private function deleteIfExists(string $filePath): void
{
if (file_exists($filePath)) {
FileHelper::unlink($filePath);
}
}
}

0 comments on commit 8676256

Please sign in to comment.