summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2017-10-21 19:27:04 -0400
committerAndrew Gallant <jamslam@gmail.com>2017-10-21 22:40:09 -0400
commitcd575d99f854110a184c731e1eab3397259a12a7 (patch)
tree5a360f91a8fc364da8c9ec4a7125f38b8ca6c419
parent1267f01c246974b7e93a4f6dbbea6801d636c128 (diff)
ignore: upgrade to walkdir 2
The uninteresting bits of this commit involve mechanical changes for updates to walkdir 2. The more interesting bits of this commit are the breaking changes, although none of them should require any significant change on users of this library. The breaking changes are as follows: * `DirEntry::path_is_symbolic_link` has been renamed to `DirEntry::path_is_symlink`. This matches the conventions in the standard library, and also the corresponding name change in walkdir. * Removed the `From<walkdir::Error> for ignore::Error` impl. This was intended to only be used internally, but was the only thing that made `walkdir` a public dependency of `ignore`. Therefore, we remove it since it seems unnecessary. * Renamed `WalkBuilder::sort_by` to `WalkBuilder::sort_by_file_name`, and changed the type of the comparator from Fn(&OsString, &OsString) -> cmp::Ordering + 'static to Fn(&OsStr, &OsStr) -> cmp::Ordering + Send + Sync + 'static The corresponding change in `walkdir` retains the `sort_by` name, but gives the comparator a pair of `&DirEntry` values instead of a pair of `&OsStr` values. Ideally, `ignore` would hand off its own pair of `&ignore::DirEntry` values, but this requires more design work. So for now, we retain previous functionality, but leave room to make a proper `sort_by` method. [breaking-change]
-rw-r--r--Cargo.lock17
-rw-r--r--Cargo.toml2
-rw-r--r--ignore/Cargo.toml3
-rw-r--r--ignore/src/lib.rs48
-rw-r--r--ignore/src/walk.rs43
-rw-r--r--src/args.rs2
6 files changed, 61 insertions, 54 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f60f3112..e853dd06 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -16,7 +16,7 @@ dependencies = [
"memmap 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "same-file 0.1.3 (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",
]
@@ -145,8 +145,9 @@ dependencies = [
"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)",
"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)",
"thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "walkdir 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -228,7 +229,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "same-file"
-version = "0.1.3"
+version = "1.0.0"
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)",
@@ -320,12 +321,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "walkdir"
-version = "1.0.7"
+version = "2.0.0"
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)",
- "same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "same-file 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -369,7 +368,7 @@ dependencies = [
"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584"
"checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b"
"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
-"checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7"
+"checksum same-file 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "70a18720d745fb9ca6a041b37cb36d0b21066006b6cff8b5b360142d4b81fb60"
"checksum simd 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "63b5847c2d766ca7ce7227672850955802fabd779ba616aeabead4c2c3877023"
"checksum simd 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a94d14a2ae1f1f110937de5fb69e494372560181c7e1739a097fcc2cee37ba0"
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"
@@ -382,6 +381,6 @@ dependencies = [
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
-"checksum walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bb08f9e670fab86099470b97cd2b252d6527f0b3cc1401acdb595ffc9dd288ff"
+"checksum walkdir 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74b57144544c33357d515400d669f9d3e1a5257326a6f6e1f5c0eb304ac8117c"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
diff --git a/Cargo.toml b/Cargo.toml
index f2a7f279..fa474322 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -44,7 +44,7 @@ memchr = "2"
memmap = "0.5"
num_cpus = "1"
regex = "0.2.1"
-same-file = "0.1.1"
+same-file = "1"
termcolor = { version = "0.3.0", path = "termcolor" }
[build-dependencies]
diff --git a/ignore/Cargo.toml b/ignore/Cargo.toml
index 0fa01090..660ee39c 100644
--- a/ignore/Cargo.toml
+++ b/ignore/Cargo.toml
@@ -24,8 +24,9 @@ lazy_static = "0.2"
log = "0.3"
memchr = "2"
regex = "0.2.1"
+same-file = "1"
thread_local = "0.3.2"
-walkdir = "1.0.7"
+walkdir = "2"
[dev-dependencies]
tempdir = "0.3.5"
diff --git a/ignore/src/lib.rs b/ignore/src/lib.rs
index d053014c..456079c1 100644
--- a/ignore/src/lib.rs
+++ b/ignore/src/lib.rs
@@ -54,6 +54,7 @@ extern crate lazy_static;
extern crate log;
extern crate memchr;
extern crate regex;
+extern crate same_file;
#[cfg(test)]
extern crate tempdir;
extern crate thread_local;
@@ -198,6 +199,29 @@ impl Error {
}
errline.with_path(path)
}
+
+ /// Build an error from a walkdir error.
+ fn from_walkdir(err: walkdir::Error) -> Error {
+ let depth = err.depth();
+ if let (Some(anc), Some(child)) = (err.loop_ancestor(), err.path()) {
+ return Error::WithDepth {
+ depth: depth,
+ err: Box::new(Error::Loop {
+ ancestor: anc.to_path_buf(),
+ child: child.to_path_buf(),
+ }),
+ };
+ }
+ let path = err.path().map(|p| p.to_path_buf());
+ let mut ig_err = Error::Io(io::Error::from(err));
+ if let Some(path) = path {
+ ig_err = Error::WithPath {
+ path: path,
+ err: Box::new(ig_err),
+ };
+ }
+ ig_err
+ }
}
impl error::Error for Error {
@@ -258,30 +282,6 @@ impl From<io::Error> for Error {
}
}
-impl From<walkdir::Error> for Error {
- fn from(err: walkdir::Error) -> Error {
- let depth = err.depth();
- if let (Some(anc), Some(child)) = (err.loop_ancestor(), err.path()) {
- return Error::WithDepth {
- depth: depth,
- err: Box::new(Error::Loop {
- ancestor: anc.to_path_buf(),
- child: child.to_path_buf(),
- }),
- };
- }
- let path = err.path().map(|p| p.to_path_buf());
- let mut ig_err = Error::Io(io::Error::from(err));
- if let Some(path) = path {
- ig_err = Error::WithPath {
- path: path,
- err: Box::new(ig_err),
- };
- }
- ig_err
- }
-}
-
#[derive(Debug, Default)]
struct PartialErrorBuilder(Vec<Error>);
diff --git a/ignore/src/walk.rs b/ignore/src/walk.rs
index 3df7933a..8a15984d 100644
--- a/ignore/src/walk.rs
+++ b/ignore/src/walk.rs
@@ -1,5 +1,5 @@
use std::cmp;
-use std::ffi::{OsStr, OsString};
+use std::ffi::OsStr;
use std::fmt;
use std::fs::{self, FileType, Metadata};
use std::io;
@@ -11,7 +11,8 @@ use std::time::Duration;
use std::vec;
use crossbeam::sync::MsQueue;
-use walkdir::{self, WalkDir, WalkDirIterator, is_same_file};
+use same_file::is_same_file;
+use walkdir::{self, WalkDir};
use dir::{Ignore, IgnoreBuilder};
use gitignore::GitignoreBuilder;
@@ -36,8 +37,8 @@ impl DirEntry {
}
/// Whether this entry corresponds to a symbolic link or not.
- pub fn path_is_symbolic_link(&self) -> bool {
- self.dent.path_is_symbolic_link()
+ pub fn path_is_symlink(&self) -> bool {
+ self.dent.path_is_symlink()
}
/// Returns true if and only if this entry corresponds to stdin.
@@ -137,12 +138,12 @@ impl DirEntryInner {
}
}
- fn path_is_symbolic_link(&self) -> bool {
+ fn path_is_symlink(&self) -> bool {
use self::DirEntryInner::*;
match *self {
Stdin => false,
- Walkdir(ref x) => x.path_is_symbolic_link(),
- Raw(ref x) => x.path_is_symbolic_link(),
+ Walkdir(ref x) => x.path_is_symlink(),
+ Raw(ref x) => x.path_is_symlink(),
}
}
@@ -199,6 +200,7 @@ impl DirEntryInner {
#[cfg(unix)]
fn ino(&self) -> Option<u64> {
+ use walkdir::DirEntryExt;
use self::DirEntryInner::*;
match *self {
Stdin => None,
@@ -244,7 +246,7 @@ impl DirEntryRaw {
&self.path
}
- fn path_is_symbolic_link(&self) -> bool {
+ fn path_is_symlink(&self) -> bool {
self.ty.is_symlink() || self.follow_link
}
@@ -404,7 +406,9 @@ pub struct WalkBuilder {
max_depth: Option<usize>,
max_filesize: Option<u64>,
follow_links: bool,
- sorter: Option<Arc<Fn(&OsString, &OsString) -> cmp::Ordering + 'static>>,
+ sorter: Option<Arc<
+ Fn(&OsStr, &OsStr) -> cmp::Ordering + Send + Sync + 'static
+ >>,
threads: usize,
}
@@ -458,7 +462,9 @@ impl WalkBuilder {
}
if let Some(ref cmp) = cmp {
let cmp = cmp.clone();
- wd = wd.sort_by(move |a, b| cmp(a, b));
+ wd = wd.sort_by(move |a, b| {
+ cmp(a.file_name(), b.file_name())
+ });
}
(p.to_path_buf(), Some(WalkEventIter::from(wd)))
}
@@ -572,16 +578,16 @@ impl WalkBuilder {
}
/// Enables all the standard ignore filters.
- ///
+ ///
/// This toggles, as a group, all the filters that are enabled by default:
- ///
+ ///
/// - [hidden()](#method.hidden)
/// - [parents()](#method.parents)
/// - [ignore()](#method.ignore)
/// - [git_ignore()](#method.git_ignore)
/// - [git_global()](#method.git_global)
/// - [git_exclude()](#method.git_exclude)
- ///
+ ///
/// They may still be toggled individually after calling this function.
///
/// This is (by definition) enabled by default.
@@ -662,7 +668,7 @@ impl WalkBuilder {
self
}
- /// Set a function for sorting directory entries.
+ /// Set a function for sorting directory entries by file name.
///
/// If a compare function is set, the resulting iterator will return all
/// paths in sorted order. The compare function will be called to compare
@@ -670,8 +676,9 @@ impl WalkBuilder {
/// entry.
///
/// Note that this is not used in the parallel iterator.
- pub fn sort_by<F>(&mut self, cmp: F) -> &mut WalkBuilder
- where F: Fn(&OsString, &OsString) -> cmp::Ordering + 'static {
+ pub fn sort_by_file_name<F>(&mut self, cmp: F) -> &mut WalkBuilder
+ where F: Fn(&OsStr, &OsStr) -> cmp::Ordering + Send + Sync + 'static
+ {
self.sorter = Some(Arc::new(cmp));
self
}
@@ -752,7 +759,7 @@ impl Iterator for Walk {
};
match ev {
Err(err) => {
- return Some(Err(Error::from(err)));
+ return Some(Err(Error::from_walkdir(err)));
}
Ok(WalkEvent::Exit) => {
self.ig = self.ig.parent().unwrap();
@@ -788,7 +795,7 @@ impl Iterator for Walk {
/// the entire contents of a directory have been enumerated.
struct WalkEventIter {
depth: usize,
- it: walkdir::Iter,
+ it: walkdir::IntoIter,
next: Option<Result<walkdir::DirEntry, walkdir::Error>>,
}
diff --git a/src/args.rs b/src/args.rs
index ff636d17..5d2e6880 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -287,7 +287,7 @@ impl Args {
wd.parents(!self.no_ignore_parent);
wd.threads(self.threads());
if self.sort_files {
- wd.sort_by(|a, b| a.cmp(b));
+ wd.sort_by_file_name(|a, b| a.cmp(b));
}
wd
}