commit a156511de4a1c8588574c045323c5cf237a850e5 Author: Heinrich Langos Date: Mon Apr 14 23:03:24 2008 +0200 Changed size tolerance for podcast cache usage to +/-5 percent. diff --git a/src/gnupod_addsong.pl b/src/gnupod_addsong.pl index 3ffec29..492e5b9 100644 --- a/src/gnupod_addsong.pl +++ b/src/gnupod_addsong.pl @@ -399,15 +399,15 @@ sub PODCAST_fetch_media { push @cachefilecandidates, $flatcachefile; foreach my $cachefile (@cachefilecandidates) { - if ( -e $cachefile && -r $cachefile && $length > (stat($cachefile))[7] ) { + if ( -e $cachefile && -r $cachefile ) { my $sizedelta = int($length) - int((stat($cachefile))[7]) ; - print "* [HTTP] Not using cached file $cachefile ... (size:".(stat($cachefile))[7]." (".$sizedelta." bytes too small))\n"; - } - if ( -e $cachefile && -r $cachefile && $length <= (stat($cachefile))[7] ) { - my $sizedelta = int((stat($cachefile))[7]) - int($length); - print "* [HTTP] Using cached file $cachefile ... (size:".(stat($cachefile))[7]."". - ($sizedelta ? " (".$sizedelta." bytes bigger than expected)" : "(matches expected length)").")\n"; - return {file=>$cachefile, status=>0}; + if (abs($sizedelta) > ($length * 0.05)) { + print "* [HTTP] Not using cached file $cachefile ... (".abs($sizedelta)." bytes too ".($sizedelta > 0 ? "small" : "big").")\n"; + } else { + print "* [HTTP] Using cached file $cachefile (size:".(stat($cachefile))[7].") ...". + ($sizedelta ? " (even though it is ".abs($sizedelta)." bytes too " . ($sizedelta>0?"small":"big") . ")" : "")."\n"; + return {file=>$cachefile, status=>0}; + } } } print "* [HTTP] Downloading $url ...\n";