summaryrefslogtreecommitdiff
path: root/it_url.class
diff options
context:
space:
mode:
authorChristian Schneider2011-03-01 13:07:24 +0000
committerChristian Schneider2011-03-01 13:07:24 +0000
commit77ed6c4e2492c8a9227925d6227d28f3d741d948 (patch)
treee9282d0afa0883266de558761c823d77d302b5ae /it_url.class
parent3dd202a8c4564442a623945213e53aa9fc70589a (diff)
downloaditools-77ed6c4e2492c8a9227925d6227d28f3d741d948.tar.gz
itools-77ed6c4e2492c8a9227925d6227d28f3d741d948.tar.bz2
itools-77ed6c4e2492c8a9227925d6227d28f3d741d948.zip
Handle keepfailed when blocked process discovers that file could not be fetched
Diffstat (limited to 'it_url.class')
-rw-r--r--it_url.class11
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