Parity log optimization

This commit is contained in:
bergware
2022-02-27 13:04:42 +01:00
parent fc5f6acd62
commit 91d2509e4d
2 changed files with 14 additions and 2 deletions
+13 -1
View File
@@ -198,9 +198,21 @@ function compress($name,$size=18,$end=6) {
function escapestring($name) {
return "\"$name\"";
}
function tail($file, $rows=1) {
$file = new SplFileObject($file);
$file->seek(SEEK_END);
$end = $file->key();
$file->seek($end-$rows);
$echo = [];
while (!$file->eof()) {
$echo[] = $file->current();
$file->next();
}
return implode($echo);
}
function last_parity_log() {
$log = '/boot/config/parity-checks.log';
[$date,$duration,$speed,$status,$error,$action,$size] = file_exists($log) ? my_explode('|',exec("tail -1 $log"),7) : array_fill(0,7,0);
[$date,$duration,$speed,$status,$error,$action,$size] = file_exists($log) ? my_explode('|',tail($log),7) : array_fill(0,7,0);
if ($date) {
[$y,$m,$d,$t] = my_preg_split('/ +/',$date,4);
$date = strtotime("$d-$m-$y $t");
+1 -1
View File
@@ -37,7 +37,7 @@ session_destroy();
function new_parity_log($timestamp) {
global $log;
return file_exists($log) ? explode('|',exec("tail -1 $log"))[0]!=$timestamp : true;
return file_exists($log) ? explode('|',tail($log))[0]!=$timestamp : true;
}
function my_clock($time) {
if (!$time) return _('less than a minute');