mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2024-12-12 19:18:24 +02:00
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.
This commit is contained in:
parent
c8227e0cf3
commit
6b2efd4d88
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user