From 60c9be5edb33f93805f1617b5e8a53d3c0b3ab22 Mon Sep 17 00:00:00 2001 From: markusbloch <> Date: Mon, 5 Jan 2015 21:26:46 +0000 Subject: [PATCH] FB_CALLMONITOR: use standard file read/write function to support use of configDb git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@7456 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- CHANGED | 1 + FHEM/72_FB_CALLMONITOR.pm | 33 ++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/CHANGED b/CHANGED index c3c7c4195..b94a4faec 100644 --- a/CHANGED +++ b/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - change: FB_CALLMONITOR: use standard file read/write function to support use of configDb - bugfix: FB_CALLMONITOR: fix phonebook file read when using configDb (Forum #30244) - feature: 70_XBMC: added commands: openmovieid, openepisodeid, addon, jsonraw (thanks to siggi85) - fix: 70_XBMC: made fork attribute to close file handles correctly diff --git a/FHEM/72_FB_CALLMONITOR.pm b/FHEM/72_FB_CALLMONITOR.pm index 66d0cd48e..0ef4b51a3 100755 --- a/FHEM/72_FB_CALLMONITOR.pm +++ b/FHEM/72_FB_CALLMONITOR.pm @@ -600,7 +600,9 @@ sub FB_CALLMONITOR_writeToCache($$$) my ($hash, $number, $txt) = @_; my $name = $hash->{NAME}; my $file = AttrVal($name, "reverse-search-cache-file", ""); - + my $err; + my @cachefile; + $file =~ s/(^\s+|\s+$)//g; $hash->{helper}{CACHE}{$number} = $txt; @@ -608,14 +610,17 @@ sub FB_CALLMONITOR_writeToCache($$$) if($file ne "") { Log3 $name, 4, "FB_CALLMONITOR ($name) - opening cache file $file for writing $number ($txt)"; - if(open(CACHEFILE, ">>$file")) + + foreach my $key (keys %{$hash->{helper}{CACHE}}) { - print CACHEFILE "$number|$txt\n"; - close(CACHEFILE); + push @cachefile, "$key|".$hash->{helper}{CACHE}{$key}; } - else + + $err = FileWrite($file,@cachefile); + + if(defined($err) && $err) { - Log3 $name, 2, "FB_CALLMONITOR ($name) - could not open cache file for writing"; + Log3 $name, 2, "FB_CALLMONITOR ($name) - could not write cache file: $err"; } } } @@ -676,8 +681,6 @@ sub FB_CALLMONITOR_readPhonebook($;$$) return "Could not read FritzBox phonebook file - $err"; } - - $phonebook = join("", @lines); Log3 $name, 2, "FB_CALLMONITOR ($name) - found FritzBox phonebook $phonebook_file"; @@ -776,7 +779,7 @@ sub FB_CALLMONITOR_loadCacheFile($;$) my @tmpline; my $count_contacts; my $name = $hash->{NAME}; - + my $err; $file = AttrVal($hash->{NAME}, "reverse-search-cache-file", "") unless(defined($file)); $file =~ s/(^\s+|\s+$)//g; @@ -785,11 +788,11 @@ sub FB_CALLMONITOR_loadCacheFile($;$) delete($hash->{helper}{CACHE}) if(defined($hash->{helper}{CACHE})); Log3 $hash->{NAME}, 3, "FB_CALLMONITOR ($name) - loading cache file $file"; - if(open(CACHEFILE, "$file")) - { - @cachefile = ; - close(CACHEFILE); - + + ($err, @cachefile) = FileRead($file); + + unless(defined($err) and $err) + { foreach my $line (@cachefile) { if(not $line =~ /^\s*$/) @@ -809,7 +812,7 @@ sub FB_CALLMONITOR_loadCacheFile($;$) } else { - Log3 $name, 3, "FB_CALLMONITOR ($name) - could not open cache file"; + Log3 $name, 3, "FB_CALLMONITOR ($name) - could not open cache file: $err"; } } }