From 7687e40293cb1eecbdcf7eb0c92621116ef4ff58 Mon Sep 17 00:00:00 2001 From: amsharma91 Date: Tue, 20 Sep 2016 18:40:47 +0530 Subject: [PATCH] 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. --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e4f4b4f36..6987c18b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -322,7 +322,11 @@ impl Worker { ) -> Result { 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(