diff options
Diffstat (limited to 'it_url.class')
-rw-r--r-- | it_url.class | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/it_url.class b/it_url.class index 76d9203..c5252aa 100644 --- a/it_url.class +++ b/it_url.class @@ -405,17 +405,19 @@ function get_cache($p = array()) if ($filemtime = it_url::_expired($path, $p['maxage'])) # Outdated(non-zero int) or non-existant(true)? { + $fileexists = $filemtime !== true; + if ($lock = it_url::_lock($path)) { # Touch existing file to prevent locking other getters while refreshing - if ($filemtime !== true) + if ($fileexists) touch($path); EDC('getcache', "new", $filemtime, $p['url'], $path); if ($result = it_url::get($p + array('filemtime' => EDC('nocache') ? null : $filemtime))) # => true means not modified (no new data fetched) $newfile = it_url::_atomicwrite($path, $result); else if ($p['keepfailed']) - $result = file_exists($path); + $result = $fileexists; else @unlink($path); # Expired and failed to get @@ -426,6 +428,11 @@ function get_cache($p = array()) # Wait for file currently being transferred EDC('getcache', "wait", $p['url'], $path); $result = it_url::_waitforlockedfile($path, $p); + + # If file could no be fetched by other thread but exists and we are in keepfailed mode then return old file + if (!$result && $p['keepfailed']) + $result = $fileexists; + } } else |