1
0
Fork 0

feat(Cache): make cache writes more atomic

Fixes #9568
pull/9580/head
Ilya Urvachev 2020-12-29 23:57:29 +03:00
parent 2406a094d3
commit e829ff80bc
No known key found for this signature in database
GPG Key ID: 07B9F50EF721A85D
1 changed files with 2 additions and 1 deletions

View File

@ -115,7 +115,8 @@ class Cache
$this->io->writeError('Writing '.$this->root . $file.' into cache', true, IOInterface::DEBUG);
try {
return file_put_contents($this->root . $file.'.tmp', $contents) !== false && rename($this->root . $file . '.tmp', $this->root . $file);
$tempFileName = $this->root . $file . uniqid('.tmp.', true);
return file_put_contents($tempFileName, $contents) !== false && rename($tempFileName, $this->root . $file);
} catch (\ErrorException $e) {
$this->io->writeError('<warning>Failed to write into cache: '.$e->getMessage().'</warning>', true, IOInterface::DEBUG);
if (preg_match('{^file_put_contents\(\): Only ([0-9]+) of ([0-9]+) bytes written}', $e->getMessage(), $m)) {