mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
92_FileLog.pm: fix seekto Problem (Forum #45221)
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@10111 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
3f92154275
commit
1f1fecba6f
@ -908,19 +908,22 @@ RESCAN:
|
|||||||
}
|
}
|
||||||
|
|
||||||
###############
|
###############
|
||||||
# this is not elegant
|
# this is not elegant. Assume, that current seek pos is after a cr/nl
|
||||||
sub
|
sub
|
||||||
seekBackOneLine($$)
|
seekBackOneLine($$)
|
||||||
{
|
{
|
||||||
my ($fh, $pos) = @_;
|
my ($fh, $pos) = @_;
|
||||||
my $buf;
|
my $buf;
|
||||||
$pos -= 2; # skip current CR/NL
|
|
||||||
$fh->seek($pos, 0);
|
while($pos > 0) { # skip current CR/NL
|
||||||
while($pos > 0 && $fh->read($buf, 1)) {
|
$fh->seek(--$pos, 0);
|
||||||
if($buf eq "\n" || $buf eq "\r") {
|
$fh->read($buf, 1);
|
||||||
$fh->seek(++$pos, 0);
|
last if($buf ne "\n" || $buf ne "\r");
|
||||||
return $pos;
|
|
||||||
}
|
}
|
||||||
|
$fh->seek($pos, 0);
|
||||||
|
|
||||||
|
while($pos > 0 && $fh->read($buf, 1)) {
|
||||||
|
return ++$pos if($buf eq "\n" || $buf eq "\r");
|
||||||
$fh->seek(--$pos, 0);
|
$fh->seek(--$pos, 0);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -943,7 +946,7 @@ FileLog_seekTo($$$$$)
|
|||||||
my $upper = $fh->tell;
|
my $upper = $fh->tell;
|
||||||
|
|
||||||
my ($lower, $next, $last) = (0, $upper/2, -1);
|
my ($lower, $next, $last) = (0, $upper/2, -1);
|
||||||
while() { # Binary search
|
for(my $iter=0; $iter<200; $iter++) { # Binary search
|
||||||
if($next == $last) {
|
if($next == $last) {
|
||||||
$fh->seek($next, 0);
|
$fh->seek($next, 0);
|
||||||
last;
|
last;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user