mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
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:

committed by
Dmitry Naumenko

parent
009682ca04
commit
4f41d1118c
@ -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);
|
||||
|
Reference in New Issue
Block a user