diff options
author | Andrew Gallant <jamslam@gmail.com> | 2016-09-24 20:45:06 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2016-09-24 20:45:06 -0400 |
commit | 6b2efd4d88b78f2e108f1984fa9dcedfeadf383d (patch) | |
tree | 4f271b504e06f9f38c81ce6070482ee2d686a8e0 /src/main.rs | |
parent | c8227e0cf3bc4e8d98de84d6068b3affe95235e5 (diff) |
If a file is empty, still try to search it.
Files like /proc/cpuinfo will advertise themselves as a normal file with
size 0. Normally, this isn't a problem, but if ripgrep decides to use a
memory map, it skipped searching if the file was empty since it's an error
to memory map an empty file. Instead of returning 0, we should just fall
back to standard read calls.
Fixes #55.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index e4f4b4f3..6987c18b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -322,7 +322,11 @@ impl Worker { ) -> Result<u64> { if try!(file.metadata()).len() == 0 { // Opening a memory map with an empty file results in an error. - return Ok(0); + // However, this may not actually be an empty file! For example, + // /proc/cpuinfo reports itself as an empty file, but it can + // produce data when it's read from. Therefore, we fall back to + // regular read calls. + return self.search(printer, path, file); } let mmap = try!(Mmap::open(file, Protection::Read)); Ok(self.args.searcher_buffer( |