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

[lintian] 01/01: Make sliding windows take open handles instead of files



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository lintian.

commit f7d45221a5691dde82280dc330f24384b208c843
Author: Niels Thykier <niels@thykier.net>
Date:   Tue Mar 18 22:43:53 2014 +0100

    Make sliding windows take open handles instead of files
    
    This allows us to use the "-T" test on an open handle instead of a
    path name.  Since the underlying "-T" has to read from the file, we
    save at least one "open/close"-cycle of the file.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 checks/cruft.pm              |  9 ++++++---
 checks/files.pm              |  8 ++++----
 lib/Lintian/SlidingWindow.pm | 13 ++++++++-----
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/checks/cruft.pm b/checks/cruft.pm
index 17cd500..a972cea 100644
--- a/checks/cruft.pm
+++ b/checks/cruft.pm
@@ -740,14 +740,16 @@ sub full_text_check {
         return;
     }
 
+    open(my $fd, '<:raw', $path);
     # allow to check only text file
-    unless(-T $path) {
+    unless (-T $fd) {
+        close($fd);
         return;
     }
 
     # some js file comments are really really long
-    my $sfd = Lintian::SlidingWindow->new('<:raw', $path, \&lc_block,
-        $isjsfile ? 8092 : 4096);
+    my $sfd
+      = Lintian::SlidingWindow->new($fd, \&lc_block,$isjsfile ? 8092 : 4096);
     my %licenseproblemhash = ();
     my $cleanjsblock = '';
 
@@ -806,6 +808,7 @@ sub full_text_check {
             }
         }
     }
+    close($fd);
     return;
 }
 
diff --git a/checks/files.pm b/checks/files.pm
index dcc3e55..4a17cb8 100644
--- a/checks/files.pm
+++ b/checks/files.pm
@@ -1825,10 +1825,9 @@ sub detect_privacy_breach {
         return;
     }
 
-    my $sfd = Lintian::SlidingWindow->new(
-        '<:raw',
-        $info->unpacked($file),
-        sub { $_=lc($_); });
+    open(my $fd, '<:raw', $info->unpacked($file));
+
+    my $sfd = Lintian::SlidingWindow->new($fd,sub { $_=lc($_); });
 
     while (my $block = $sfd->readwindow()) {
         # try generic fragment tagging
@@ -1936,6 +1935,7 @@ sub detect_privacy_breach {
             }
         }
     }
+    close($fd);
     return;
 }
 
diff --git a/lib/Lintian/SlidingWindow.pm b/lib/Lintian/SlidingWindow.pm
index c60d0a8..a88f27c 100644
--- a/lib/Lintian/SlidingWindow.pm
+++ b/lib/Lintian/SlidingWindow.pm
@@ -27,8 +27,7 @@ use Carp qw(croak);
 use Lintian::Util qw(strip);
 
 sub new {
-    my ($class, $mode, $file, $blocksub, $blocksize) = @_;
-    open(my $handle, $mode, $file);
+    my ($class, $handle, $blocksub, $blocksize) = @_;
 
     $blocksize //= 4096;
 
@@ -129,10 +128,14 @@ file in memory.
 
 =over 4
 
-=item new(mode,file,[blocksub], [block size])
+=item new(HANDLE[, BLOCKSUB[, BLOCKSIZE]])
 
-Create a new sliding window for file file using mode mode. Optionally run blocksub against
-each block. Note that blocksub should apply transform byte by byte and does not depend of context.
+Create a new sliding window by reading from a given HANDLE, which must
+be open for reading. Optionally run BLOCKSUB against each block. Note
+that BLOCKSUB should apply transform byte by byte and does not depend
+of context.
+
+Each window consists of up to two blocks of BLOCKSIZE characters.
 
 =back
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: