diff options
author | Christian Schneider | 2011-03-01 13:07:24 +0000 |
---|---|---|
committer | Christian Schneider | 2011-03-01 13:07:24 +0000 |
commit | 77ed6c4e2492c8a9227925d6227d28f3d741d948 (patch) | |
tree | e9282d0afa0883266de558761c823d77d302b5ae | |
parent | 3dd202a8c4564442a623945213e53aa9fc70589a (diff) | |
download | itools-77ed6c4e2492c8a9227925d6227d28f3d741d948.tar.gz itools-77ed6c4e2492c8a9227925d6227d28f3d741d948.tar.bz2 itools-77ed6c4e2492c8a9227925d6227d28f3d741d948.zip |
Handle keepfailed when blocked process discovers that file could not be fetched
-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 |