From c8de9a0d225f9f950a38129e03486e5c51fe9eeb Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Fri, 4 Dec 2015 15:41:21 +0000 Subject: [PATCH] 92_FileLog.pm: seekTo bug (Forum #45005) git-svn-id: https://svn.fhem.de/fhem/trunk@10085 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/92_FileLog.pm | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/fhem/FHEM/92_FileLog.pm b/fhem/FHEM/92_FileLog.pm index 4030dbcf8..987e83399 100755 --- a/fhem/FHEM/92_FileLog.pm +++ b/fhem/FHEM/92_FileLog.pm @@ -942,8 +942,13 @@ FileLog_seekTo($$$$$) $fh->seek(0, 2); # Go to the end my $upper = $fh->tell; - my ($lower, $next, $last) = (0, $upper/2, 0); + my ($lower, $next, $last) = (0, $upper/2, -1); while() { # Binary search + if($next == $last) { + $fh->seek($next, 0); + last; + } + $fh->seek($next, 0); my $data = <$fh>; if(!$data) { @@ -952,24 +957,8 @@ FileLog_seekTo($$$$$) } if($reformatFn) { no strict; $data = &$reformatFn($data); use strict; } if($data !~ m/^\d\d\d\d-\d\d-\d\d_\d\d:\d\d:\d\d /o) { - $next = $fh->tell; - $data = <$fh>; - if(!$data) { - $last = seekBackOneLine($fh, $next); - last; - } - if($reformatFn) { no strict; $data = &$reformatFn($data); use strict; } - - # If the second line is longer then the first, - # binary search will never get it: - if($next eq $last && $data ge $ts) { - $last = seekBackOneLine($fh, $next); - last; - } - } - if($next eq $last) { - $fh->seek($next, 0); - last; + $next = seekBackOneLine($fh, $fh->tell); + next; } $last = $next;