[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.6-94-g6f510da



The following commit has been merged in the master branch:
commit 29eb99ae4a7d20f0718c0ca0434459b0802dafa8
Author: Niels Thykier <niels@thykier.net>
Date:   Sat Apr 7 15:38:05 2012 +0200

    L::Util: Support openhandles in slurp_entire_file
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/lib/Lintian/Util.pm b/lib/Lintian/Util.pm
index c58db29..6925658 100644
--- a/lib/Lintian/Util.pm
+++ b/lib/Lintian/Util.pm
@@ -55,6 +55,7 @@ use FileHandle;
 use Lintian::Command qw(spawn);
 use Lintian::Output qw(string);
 use Digest::MD5;
+use Scalar::Util qw(openhandle);
 
 # general function to read dpkg control files
 # this function can parse output of `dpkg-deb -f', .dsc,
@@ -226,13 +227,23 @@ sub _ensure_file_is_sane {
     return 0;
 }
 
+# Reads an entire file(-handle) and return it as a scalar.
+#
+# NB: When given a handle, it will *not* close the handle for
+# the caller.
 sub slurp_entire_file {
     my $file = shift;
-    open(C, '<', $file)
-        or fail("cannot open file $file for reading: $!");
+    my $fd;
+    my $res;
+    if (openhandle $file) {
+        $fd = $file;
+    } else {
+        open $fd, '<', $file
+            or fail ("cannot open file $file for reading: $!");
+    }
     local $/;
-    local $_ = <C>;
-    close(C);
+    local $_ = <$fd>;
+    close $fd unless openhandle $file;
     return $_;
 }
 

-- 
Debian package checker


Reply to: