From 4982a6645c9be2b5c243f0c0a87770736e757e79 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 18 Jun 2019 14:49:23 -0400 Subject: [PATCH] Fix crash on Windows | resolves #37 --- src/input.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/input.rs b/src/input.rs index 5c1ac40..16e4fe7 100644 --- a/src/input.rs +++ b/src/input.rs @@ -47,20 +47,20 @@ impl Replacer { match c { 'c' => { regex.case_insensitive(false); - } + }, 'i' => { regex.case_insensitive(true); - } + }, 'm' => { regex.multi_line(true); - } + }, 'w' => { regex = regex::bytes::RegexBuilder::new(&format!( "\\b{}\\b", look_for )); - } - _ => {} + }, + _ => {}, }; } }; @@ -110,6 +110,9 @@ impl Replacer { mmap_target.deref_mut().write_all(&replaced)?; mmap_target.flush()?; + drop(source); + drop(mmap_source); + target.persist(path)?; Ok(()) } @@ -128,7 +131,7 @@ impl Replacer { handle.write_all(&self.replace(&buffer))?; } Ok(()) - } + }, (Source::Files(paths), true) => { use rayon::prelude::*; @@ -137,7 +140,7 @@ impl Replacer { .map(|p| self.replace_file(p).map_err(Error::log)) .collect::>>(); Ok(()) - } + }, (Source::Files(paths), false) => { let stdout = std::io::stdout(); let mut handle = stdout.lock(); @@ -152,7 +155,7 @@ impl Replacer { }) .collect::>>()?; Ok(()) - } + }, } } }