Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ack doesn't search zero length files #102

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

Ack doesn't search zero length files #102

bitsed opened this issue Oct 19, 2009 · 4 comments

Comments

@bitsed
Copy link

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
Copy link
Collaborator

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

@bitsed
Copy link
Author

bitsed commented Oct 19, 2009

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

@bitsed
Copy link
Author

bitsed commented Oct 19, 2009

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

@hoelzro
Copy link
Collaborator

hoelzro commented Aug 28, 2013

Closing as duplicate of #89.

@hoelzro hoelzro closed this as completed Aug 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants