Ack doesn't search zero length files #102

Closed
bitsed opened this Issue Oct 19, 2009 · 4 comments

Comments

Projects
None yet
3 participants
@bitsed

bitsed commented Oct 19, 2009

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

This comment has been minimized.

Show comment
Hide comment
@petdance

petdance Oct 19, 2009

Collaborator

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

Collaborator

petdance commented Oct 19, 2009

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

@bitsed

This comment has been minimized.

Show comment
Hide comment
@bitsed

bitsed Oct 19, 2009

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

bitsed commented Oct 19, 2009

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

@bitsed

This comment has been minimized.

Show comment
Hide comment
@bitsed

bitsed Oct 19, 2009

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

bitsed commented Oct 19, 2009

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

@hoelzro

This comment has been minimized.

Show comment
Hide comment
@hoelzro

hoelzro Aug 28, 2013

Collaborator

Closing as duplicate of #89.

Collaborator

hoelzro commented Aug 28, 2013

Closing as duplicate of #89.

@hoelzro hoelzro closed this Aug 28, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment