bug #39788 [Cache] fix possible collision when writing tmp file in filesystem adapter (nicolas-grekas)
This PR was merged into the 4.4 branch.
Discussion
----------
[Cache] fix possible collision when writing tmp file in filesystem adapter
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #39786
| License | MIT
| Doc PR | -
Commits
-------
340d15e400
[Cache] fix possible collision when writing tmp file in filesystem adapter
This commit is contained in:
commit
2852a42468
@ -93,9 +93,20 @@ trait FilesystemCommonTrait
|
|||||||
set_error_handler(__CLASS__.'::throwError');
|
set_error_handler(__CLASS__.'::throwError');
|
||||||
try {
|
try {
|
||||||
if (null === $this->tmp) {
|
if (null === $this->tmp) {
|
||||||
$this->tmp = $this->directory.uniqid('', true);
|
$this->tmp = $this->directory.bin2hex(random_bytes(6));
|
||||||
}
|
}
|
||||||
file_put_contents($this->tmp, $data);
|
try {
|
||||||
|
$h = fopen($this->tmp, 'x');
|
||||||
|
} catch (\ErrorException $e) {
|
||||||
|
if (false === strpos($e->getMessage(), 'File exists')) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tmp = $this->directory.bin2hex(random_bytes(6));
|
||||||
|
$h = fopen($this->tmp, 'x');
|
||||||
|
}
|
||||||
|
fwrite($h, $data);
|
||||||
|
fclose($h);
|
||||||
|
|
||||||
if (null !== $expiresAt) {
|
if (null !== $expiresAt) {
|
||||||
touch($this->tmp, $expiresAt);
|
touch($this->tmp, $expiresAt);
|
||||||
|
Reference in New Issue
Block a user