ack3 icon indicating copy to clipboard operation
ack3 copied to clipboard

Silent hanging on encountering a ./- file

Open Smylers opened this issue 10 years ago • 3 comments

If ack encounters a file called - in the current directory then it silently hangs for ever.

It seems that the file - is being treated as though it were a command-line argument -, which would indicate to read from standard input (and would indeed correctly cause ack to hang if there weren't anything on stdin). But a file called ./- is unambiguously a file; it isn't a command-line argument, and it isn't stdin.

Steps to reproduce. This works as expected:

$ mkdir bug_551
$ cd bug_551
$ echo aiieee > Batman.txt
$ ack i
Batman.txt
1:aiieee

Creating ./- causes the hang:

$ touch ./-
$ ack i

Explicitly listing the files to search avoids ./- getting in the way:

$ ack i *txt
aiieee

Bug beyondgrep/ack3#269 is sort-of the opposite of this, but they may overlap: both are influenced by ./-.

Smylers avatar Apr 30 '15 10:04 Smylers

A better demo that ./- is actually making ack read from stdin:

$ echo zam > ./-
$ echo thwapp | ack --nofilter a
-
1:thwapp

Batman.txt
1:aiieee

See that ack displays the “thwapp” from stdin, not the “zam” from ./-.

Smylers avatar Apr 30 '15 10:04 Smylers

What does grep do in a similar situation?

petdance avatar Apr 30 '15 12:04 petdance

What does grep do in a similar situation?

It just treats a file called - that it encounters on the file system as it would any other file:

$ echo thwapp | grep -r a
-:zam
Batman.txt:aiieee

But a - passed as an argument is treated as stdin:

$ echo thwapp | grep -r a -
thwapp

And an argument - can be mixed with other file/directory arguments, keeping stdin distinct from ./-:

$ echo thwapp | grep -r a - .
(standard input):thwapp
./-:zam
./Batman.txt:aiieee

Smylers avatar Apr 30 '15 14:04 Smylers