"Fixes #3717, Temp files read/write errors under load"

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6205 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-12-22 22:17:42 +00:00
parent b99ac8de46
commit 63a4e2e899

View file

@ -522,6 +522,7 @@ if (!function_exists('clone')) {
if ($write === false) { if ($write === false) {
return false; return false;
} else { } else {
@fclose($res);
return $write; return $write;
} }
} }
@ -558,25 +559,23 @@ if (!function_exists('clone')) {
$filename = TMP . $path; $filename = TMP . $path;
break; break;
} }
$timediff = $expires - $now; $timediff = $expires - $now;
$filetime = false; $filetime = false;
if (file_exists($filename)) { if (file_exists($filename)) {
$filetime = @filemtime($filename); $filetime = @filemtime($filename);
} }
if ($data === null) { if ($data === null) {
// Read data from file
if (file_exists($filename) && $filetime !== false) { if (file_exists($filename) && $filetime !== false) {
if ($filetime + $timediff < $now) { if ($filetime + $timediff < $now) {
// File has expired
@unlink($filename); @unlink($filename);
} else { } else {
$data = file_get_contents($filename); $data = @file_get_contents($filename);
} }
} }
} elseif (is_writable(dirname($filename))) { } elseif (is_writable(dirname($filename))) {
file_put_contents($filename, $data); @file_put_contents($filename, $data);
} }
return $data; return $data;
} }