Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Ack doesn't search zero length files #102

Closed
bitsed opened this Issue · 4 comments

3 participants

@bitsed

Some operating systems (notably Linux) provide zero length files containing system information. Ack version 1.90 doesn't work with these files since it skips searching of all zero length files. The patch below attempts to address this issue.

--- /usr/bin/ack        2009-10-19 11:14:59.919362762 -0700
+++ bin/ack     2009-10-19 11:57:05.632362838 -0700        
@@ -2481,21 +2481,24 @@                                    
                                                           
     return 1 if $opt->{v};                                

-    my $size = -s $self->{fh};
-    if ( $size == 0 ) {
-        return 0;
-    }
-    elsif ( $size > 100_000 ) {
-        return 1;
+    if ( -s $self->{fh} > 100_000 ) {
+       return 1;
     }

     my $buffer;
-    my $rc = sysread( $self->{fh}, $buffer, $size );
+    my $size;
+    my $rc;
+    do {
+        my $inbuf;
+        $size += $rc = sysread( $self->{fh}, $inbuf, 100_000 );
+        $buffer .= $inbuf;
+    } while ($rc != 0);
+
     if ( not defined $rc ) {
         App::Ack::warn( "$self->{filename}: $!" );
         return 1;
     }
-    return 0 unless $rc && ( $rc == $size );
+    return 0 unless $size;

     my $regex = $opt->{regex};
     return $buffer =~ /$regex/m;
@petdance
Owner

I don't understand why it would be bad to not search 0-length files.

@bitsed

I think it's not searching zero length files that don't match.

@bitsed

This issue looks like it's a duplicate of issue 89.

@hoelzro
Collaborator

Closing as duplicate of #89.

@hoelzro hoelzro closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.