diff --git a/gancioff b/gancioff index a4b5a02..6dc15b8 100755 --- a/gancioff +++ b/gancioff @@ -301,23 +301,24 @@ if (file_exists($conf['state_file_absolute_path'])) { if (!is_readable($conf['state_file_absolute_path'])) dieYoung("Error: «{$conf['state_file_absolute_path']}» exists but it’s not readable.\n",1); if (!is_writeable($conf['state_file_absolute_path'])) dieYoung("Error: «{$conf['state_file_absolute_path']}» exists but it’s not writable.\n",1); $guids=[]; - $buff=file($conf['state_file_absolute_path'],FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); + $buff=file($conf['state_file_absolute_path'],); $graceTime=365*24*60*60; $graceLine=time()-$graceTime; $i=0; - $fh=fopen($conf['state_file_absolute_path'],'w'); + $buff=file($conf['state_file_absolute_path'],FILE_IGNORE_NEW_LINES); foreach ($buff as $key=>$val) { if (preg_match('#^(\d+)\t([a-z0-9]{64})\t(\S+)$#',$val,$matches)===1) { - if ($matches[1]+0>=$graceLine) { - fwrite($fh,"{$matches[1]}\t{$matches[2]}\t{$matches[3]}\n"); + if ($matches[1]+0>=$graceLine) $guids[$matches[3]]=['timestamp'=>$matches[1], 'hash'=>$matches[2]]; - } else { + else $i++; - } } else { - fwrite(STDERR,"Warning: in state file «{$conf['state_file_absolute_path']}», line ".($key+1)." had unexpected format.\n"); + dieYoung("Error: in state file «{$conf['state_file_absolute_path']}», line ".($key+1)." has unexpected format.\n",1); } } + $fh=fopen($conf['state_file_absolute_path'],'w'); + foreach ($guids as $key=>$val) + fwrite($fh,"{$val['timestamp']}\t{$val['hash']}\t{$key}\n"); fclose($fh); vecho($opts['verbose'],'Info: got '.count($guids)." GUID(s) for already posted event(s) from state file «{$conf['state_file_absolute_path']}»; removed {$i} line(s) older than one year.\n"); } elseif (is_null($opts['do-post']) && !$opts['test']) {