From 263e8f92b98ca883362c59677e23255fabfff307 Mon Sep 17 00:00:00 2001 From: Dan Burkert Date: Sat, 28 Oct 2017 15:32:43 -0700 Subject: [PATCH] Update to memmap 0.6 `memmap` 0.6.0 introduces major API changes in anticipation of a 1.0 release. See https://github.com/danburkert/memmap-rs/releases/tag/0.6.0 for more information. CC danburkert/memmap-rs#33. --- Cargo.lock | 60 +++++++++++++++++++++------------------------------ Cargo.toml | 2 +- src/worker.rs | 6 +++--- 3 files changed, 28 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61f77637..5576dfd1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,25 +1,3 @@ -[root] -name = "ripgrep" -version = "0.7.1" -dependencies = [ - "atty 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "bytecount 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding_rs 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "grep 0.1.7", - "ignore 0.3.1", - "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memmap 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "same-file 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 0.3.3", -] - [[package]] name = "aho-corasick" version = "0.6.3" @@ -104,16 +82,6 @@ name = "fnv" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "fs2" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "globset" version = "0.2.1" @@ -193,9 +161,8 @@ dependencies = [ [[package]] name = "memmap" version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/danburkert/memmap-rs#ab3a277c8909d86dbef569a9f5424265574a03ff" dependencies = [ - "fs2 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -240,6 +207,28 @@ name = "regex-syntax" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "ripgrep" +version = "0.7.1" +dependencies = [ + "atty 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bytecount 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)", + "encoding_rs 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "grep 0.1.7", + "ignore 0.3.1", + "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memmap 0.5.2 (git+https://github.com/danburkert/memmap-rs)", + "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "same-file 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "termcolor 0.3.3", +] + [[package]] name = "same-file" version = "1.0.0" @@ -375,14 +364,13 @@ dependencies = [ "checksum encoding_rs 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f5215aabf22b83153be3ee44dfe3f940214541b2ce13d419c55e7a115c8c51a9" "checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" "checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344" -"checksum fs2 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9ab76cfd2aaa59b7bf6688ad9ba15bbae64bff97f04ea02144cfd3443e5c2866" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9e5e58fa1a4c3b915a561a78a22ee0cac6ab97dca2504428bc1cb074375f8d5" "checksum libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)" = "56cce3130fd040c28df6f495c8492e5ec5808fb4c9093c310df02b0c8f030148" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" "checksum memchr 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e01e64d9017d18e7fc09d8e4fe0e28ff6931019e979fb8019319db7ca827f8a6" -"checksum memmap 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "46f3c7359028b31999287dae4e5047ddfe90a23b7dca2282ce759b491080c99b" +"checksum memmap 0.5.2 (git+https://github.com/danburkert/memmap-rs)" = "" "checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d" "checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" diff --git a/Cargo.toml b/Cargo.toml index 5b57fb82..86fbb756 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ lazy_static = "0.2" libc = "0.2" log = "0.3" memchr = "2" -memmap = "0.5" +memmap = "0.6" num_cpus = "1" regex = "0.2.1" same-file = "1" diff --git a/src/worker.rs b/src/worker.rs index 51b7f64c..9aa0fdc0 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -5,7 +5,7 @@ use std::path::Path; use encoding_rs::Encoding; use grep::Grep; use ignore::DirEntry; -use memmap::{Mmap, Protection}; +use memmap::Mmap; use termcolor::WriteColor; use decoder::DecodeReader; @@ -290,8 +290,8 @@ impl Worker { // regular read calls. return self.search(printer, path, file); } - let mmap = try!(Mmap::open(file, Protection::Read)); - let buf = unsafe { mmap.as_slice() }; + let mmap = unsafe { try!(Mmap::map(file)) }; + let buf = &*mmap; if buf.len() >= 3 && Encoding::for_bom(buf).is_some() { // If we have a UTF-16 bom in our memory map, then we need to fall // back to the stream reader, which will do transcoding.