diff options
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | src/lib.rs | 30 | ||||
-rw-r--r-- | src/tests.rs | 15 |
5 files changed, 34 insertions, 22 deletions
diff --git a/.travis.yml b/.travis.yml index 7cdbe8f..42b1d4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: rust matrix: include: - os: linux - rust: 1.17.0 + rust: 1.23.0 - os: linux rust: stable - os: linux @@ -1,7 +1,6 @@ [package] name = "walkdir" -# remember to update html_root_url -version = "2.1.4" #:version +version = "2.2.1" #:version authors = ["Andrew Gallant <jamslam@gmail.com>"] description = "Recursively walk a directory." documentation = "https://docs.rs/walkdir/" @@ -24,7 +23,7 @@ version = "0.3" features = ["std", "winnt"] [dev-dependencies] -docopt = "0.8" +docopt = "1" quickcheck = { version = "0.6", default-features = false } rand = "0.4" serde = "1" @@ -20,7 +20,7 @@ Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org). To use this crate, add `walkdir` as a dependency to your project's `Cargo.toml`: -``` +```toml [dependencies] walkdir = "2" ``` @@ -111,7 +111,7 @@ allocations as possible. I haven't recorded any benchmarks, but here are some things you can try with a local checkout of `walkdir`: -``` +```sh # The directory you want to recursively walk: DIR=$HOME @@ -8,7 +8,7 @@ efficiently skip descending into directories. To use this crate, add `walkdir` as a dependency to your project's `Cargo.toml`: -```text +```toml [dependencies] walkdir = "2" ``` @@ -103,7 +103,6 @@ for entry in walker.filter_entry(|e| !is_hidden(e)) { [`filter_entry`]: struct.IntoIter.html#method.filter_entry */ -#![doc(html_root_url = "https://docs.rs/walkdir/2.0.0")] #![deny(missing_docs)] #[cfg(test)] @@ -624,7 +623,7 @@ pub struct DirEntry { /// The file type. Necessary for recursive iteration, so store it. ty: FileType, /// Is set when this entry was created from a symbolic link and the user - /// excepts the iterator to follow symbolic links. + /// expects the iterator to follow symbolic links. follow_link: bool, /// The depth at which this entry was generated relative to the root. depth: usize, @@ -651,7 +650,7 @@ impl Iterator for IntoIter { /// an error value. The error will be wrapped in an Option::Some. fn next(&mut self) -> Option<Result<DirEntry>> { if let Some(start) = self.start.take() { - let dent = itry!(DirEntry::from_link(0, start)); + let dent = itry!(DirEntry::from_path(0, start, false)); if let Some(result) = self.handle_entry(dent) { return Some(result); } @@ -886,7 +885,11 @@ impl IntoIter { } fn follow(&self, mut dent: DirEntry) -> Result<DirEntry> { - dent = DirEntry::from_link(self.depth, dent.path().to_path_buf())?; + dent = DirEntry::from_path( + self.depth, + dent.path().to_path_buf(), + true, + )?; // The only way a symlink can cause a loop is if it points // to a directory. Otherwise, it always points to a leaf // and we can omit any loop checks. @@ -1117,8 +1120,6 @@ impl DirEntry { #[cfg(not(any(unix, windows)))] fn from_entry(depth: usize, ent: &fs::DirEntry) -> Result<DirEntry> { - use std::os::unix::fs::DirEntryExt; - let ty = ent.file_type().map_err(|err| { Error::from_path(depth, ent.path(), err) })?; @@ -1131,21 +1132,21 @@ impl DirEntry { } #[cfg(windows)] - fn from_link(depth: usize, pb: PathBuf) -> Result<DirEntry> { + fn from_path(depth: usize, pb: PathBuf, link: bool) -> Result<DirEntry> { let md = fs::metadata(&pb).map_err(|err| { Error::from_path(depth, pb.clone(), err) })?; Ok(DirEntry { path: pb, ty: md.file_type(), - follow_link: true, + follow_link: link, depth: depth, metadata: md, }) } #[cfg(unix)] - fn from_link(depth: usize, pb: PathBuf) -> Result<DirEntry> { + fn from_path(depth: usize, pb: PathBuf, link: bool) -> Result<DirEntry> { use std::os::unix::fs::MetadataExt; let md = fs::metadata(&pb).map_err(|err| { @@ -1154,23 +1155,21 @@ impl DirEntry { Ok(DirEntry { path: pb, ty: md.file_type(), - follow_link: true, + follow_link: link, depth: depth, ino: md.ino(), }) } #[cfg(not(any(unix, windows)))] - fn from_link(depth: usize, pb: PathBuf) -> Result<DirEntry> { - use std::os::unix::fs::MetadataExt; - + fn from_path(depth: usize, pb: PathBuf, link: bool) -> Result<DirEntry> { let md = fs::metadata(&pb).map_err(|err| { Error::from_path(depth, pb.clone(), err) })?; Ok(DirEntry { path: pb, ty: md.file_type(), - follow_link: true, + follow_link: link, depth: depth, }) } @@ -1206,7 +1205,6 @@ impl Clone for DirEntry { ty: self.ty, follow_link: self.follow_link, depth: self.depth, - ino: self.ino, } } } diff --git a/src/tests.rs b/src/tests.rs index be2f89b..8847323 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -516,6 +516,21 @@ fn walk_dir_sym_root() { assert_eq!(got, vec!["foo/alink/", "foo/alink/a", "foo/alink/b"]); } +// See: https://github.com/BurntSushi/ripgrep/issues/984 +#[test] +#[cfg(unix)] +fn first_path_not_symlink() { + let exp = td("foo", vec![]); + let (tmp, _got) = dir_setup(&exp); + + let dents = WalkDir::new(tmp.path().join("foo")) + .into_iter() + .collect::<Result<Vec<_>, _>>() + .unwrap(); + assert_eq!(1, dents.len()); + assert!(!dents[0].path_is_symlink()); +} + #[test] #[cfg(unix)] fn walk_dir_sym_detect_no_follow_no_loop() { |