[weboob] [PATCH 2/2] Check if the file isn't empty before reading cache

theo theocrite at theocrite.org
Mon Mar 19 14:11:58 CET 2012


Signed-off-by: theo <theocrite at theocrite.org>
---
 contrib/freemobile-munin |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/contrib/freemobile-munin b/contrib/freemobile-munin
index 20f9748..603dbb5 100755
--- a/contrib/freemobile-munin
+++ b/contrib/freemobile-munin
@@ -108,10 +108,14 @@ sub fetch {
         my @cache_data = <$cache_fh>;
         close $cache_fh or croak "unable to close: $ERRNO";
 
-        # Data is still fresh. Display cached values and exit.
-        if ( time - $cache_data[0] < $refreshtime ) {
-            print join q{}, @cache_data[ 1 .. $#cache_data ];
-            exit 0;
+        # File not empty?
+        if ( @cache_data > 0 ) {
+
+            # Data is still fresh. Display cached values and exit.
+            if ( time - $cache_data[0] < $refreshtime ) {
+                print join q{}, @cache_data[ 1 .. $#cache_data ];
+                exit 0;
+            }
         }
     }
 
-- 
1.7.9.1



More information about the weboob mailing list