From ddcb9c8da27786a251e3ad8a719dacbacdf8e2bc Mon Sep 17 00:00:00 2001 From: Jacob Thomason Date: Tue, 12 Dec 2023 03:23:24 -0500 Subject: [PATCH] fwrite doesn't allow null - set to empty string --- lib/config/sfConfigCache.class.php | 35 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/config/sfConfigCache.class.php b/lib/config/sfConfigCache.class.php index 1b0a7f564..6280b7242 100644 --- a/lib/config/sfConfigCache.class.php +++ b/lib/config/sfConfigCache.class.php @@ -312,24 +312,22 @@ protected function loadConfigHandlers() */ protected function writeCacheFile($config, $cache, $data) { - $current_umask = umask(0000); - $cacheDir = dirname($cache); - - // Seems like there may be a situation where we're getting a file written instead of a dir at - // /tmp/cache/mypost/dev/config. Checking if it's a file, removing it and then continuing on. - // Getting error that we cannot unlink a dir. Even with this check in place. And, permissions - // are correct as well. I have no idea what's going on here. - if (!is_dir($cacheDir)) - { - if (file_exists($cacheDir)) { - unlink($cacheDir); - } + $current_umask = umask(0000); + $cacheDir = dirname($cache); + + // Seems like there may be a situation where we're getting a file written instead of a dir at + // /tmp/cache/mypost/dev/config. Checking if it's a file, removing it and then continuing on. + // Getting error that we cannot unlink a dir. Even with this check in place. And, permissions + // are correct as well. I have no idea what's going on here. + if (!is_dir($cacheDir)) { + if (file_exists($cacheDir)) { + unlink($cacheDir); + } - if (!mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) - { - throw new \sfCacheException(sprintf('Failed to make cache directory "%s" while generating cache for configuration file "%s".', $cacheDir, $config)); + if (!mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) { + throw new \sfCacheException(sprintf('Failed to make cache directory "%s" while generating cache for configuration file "%s".', $cacheDir, $config)); + } } - } $tmpFile = tempnam($cacheDir, basename($cache)); @@ -337,6 +335,11 @@ protected function writeCacheFile($config, $cache, $data) throw new sfCacheException(sprintf('Failed to write cache file "%s" generated from configuration file "%s".', $tmpFile, $config)); } + // If the data is empty, there is nothing to do here + if (empty($data)) { + $data = ''; + } + @fwrite($fp, $data); @fclose($fp);