FileCache: rebuild cache file before touch when different file owner (#16120)

* Test Travis envs

* The fix

* posix_geteuid only exists on Linux

* Added PR to changelog
This commit is contained in:
Filippo Tessarotto
2018-04-22 08:49:07 +02:00
committed by Dmitry Naumenko
parent 009682ca04
commit 4f41d1118c
4 changed files with 46 additions and 0 deletions

View File

@ -141,6 +141,12 @@ class FileCache extends Cache
if ($this->directoryLevel > 0) {
@FileHelper::createDirectory(dirname($cacheFile), $this->dirMode, true);
}
// If ownership differs the touch call will fail, so we try to
// rebuild the file from scratch by deleting it first
// https://github.com/yiisoft/yii2/pull/16120
if (is_file($cacheFile) && function_exists('posix_geteuid') && fileowner($cacheFile) !== posix_geteuid()) {
@unlink($cacheFile);
}
if (@file_put_contents($cacheFile, $value, LOCK_EX) !== false) {
if ($this->fileMode !== null) {
@chmod($cacheFile, $this->fileMode);