Skip to content

Commit

Permalink
fwrite doesn't allow null - set to empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
oojacoboo committed Dec 12, 2023
1 parent 63c3800 commit ddcb9c8
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions lib/config/sfConfigCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,31 +312,34 @@ 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));

if (!$fp = @fopen($tmpFile, 'wb')) {
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);

Expand Down

0 comments on commit ddcb9c8

Please sign in to comment.