diff options
author | chris <chris@jalakai.co.uk> | 2006-09-24 01:51:09 +0200 |
---|---|---|
committer | chris <chris@jalakai.co.uk> | 2006-09-24 01:51:09 +0200 |
commit | 40b33eff69a8a44da0ab6962d50f2027bcfc33b6 (patch) | |
tree | 22d35a8651cd42093b0a55670b28528eac2bf3b5 /lib/exe | |
parent | 44a35da6ab4b9a02117df84a2208a57b8f339ee6 (diff) | |
download | rpg-40b33eff69a8a44da0ab6962d50f2027bcfc33b6.tar.gz rpg-40b33eff69a8a44da0ab6962d50f2027bcfc33b6.tar.bz2 |
fix recent changes cache ordering
This patch fixes a bug in indexer.php which resulted in the order
of the recent changes cache being reversed each time it was trimmed.
It also adds sorting to both getRecents() and runTrimRecentChanges()
as a defensive measure against the order of the file being corrupted.
darcs-hash:20060923235109-9b6ab-0f4062c1b02449cce9382426174cd22d71387e5a.gz
Diffstat (limited to 'lib/exe')
-rw-r--r-- | lib/exe/indexer.php | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 649bb6f29..5cd030976 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -62,6 +62,7 @@ function runTrimRecentChanges() { if (@file_exists($conf['changelog']) && (filectime($conf['changelog'])+86400)<time() && !@file_exists($conf['changelog'].'_tmp')) { + io_lock($conf['changelog']); $lines = file($conf['changelog']); if (count($lines)<$conf['recent']) { @@ -69,23 +70,23 @@ function runTrimRecentChanges() { io_unlock($conf['changelog']); return true; } - // trim changelog + io_saveFile($conf['changelog'].'_tmp', ''); // presave tmp as 2nd lock - $kept = 0; $trim_time = time() - $conf['recent_days']*86400; $out_lines = array(); - // check lines from newest to oldest - for ($i = count($lines)-1; $i >= 0; $i--) { - $tmp = parseChangelogLine($lines[$i]); - if ($tmp===false) { continue; } - if ($tmp['date']>$trim_time || $kept<$conf['recent']) { - array_push($out_lines, implode("\t", $tmp)."\n"); - $kept++; - } else { - // no more lines worth keeping - break; - } + + for ($i=0; $i<count($lines); $i++) { + $log = parseChangelogLine($lines[$i]); + if ($log === false || $log['date'] < $trim_time) continue; // discard old lines + $out_lines[$log['date']] = $lines[$i]; // preserve the rest } + + ksort($out_lines); // sort lines, just in case! + if (count($out_lines) > $conf['recent']) { + $out_lines = array_slice($out_lines,-$conf['recent']); // trim list to one page + } + + // save trimmed changelog io_saveFile($conf['changelog'].'_tmp', implode('', $out_lines)); @unlink($conf['changelog']); if (!rename($conf['changelog'].'_tmp', $conf['changelog'])) { |