Skip to content

Commit

Permalink
Adding a file_exists() check before unlinking cache files.
Browse files Browse the repository at this point in the history
This prevents issues where two concurrent requests could
be clearing the same cache files.
Fixes #1936
  • Loading branch information
markstory committed Aug 27, 2011
1 parent 1a872e6 commit 4a7bd03
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Cake/Cache/Engine/FileEngine.php
Expand Up @@ -240,7 +240,9 @@ public function clear($check) {
}
$path = $this->_File->getRealPath();
$this->_File = null;
unlink($path);
if (file_exists($path)) {
unlink($path);
}
}
$dir->close();
return true;
Expand Down

2 comments on commit 4a7bd03

@davidsteinsland
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not help with the race conditions. The only way to fix the problem is by:

@unlink ($path);

Not even if (file_exists ($path)).

@markstory
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, did you want to do a pull request to improve this?

Please sign in to comment.