diff --git a/Cargo.lock b/Cargo.lock index 3b62b44be9ff..c7c709e0eac2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5530,9 +5530,9 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "walkdir" -version = "2.3.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", "winapi", diff --git a/third_party/rust/walkdir/.cargo-checksum.json b/third_party/rust/walkdir/.cargo-checksum.json index aadb1e93b9b9..1002a325a9dc 100644 --- a/third_party/rust/walkdir/.cargo-checksum.json +++ b/third_party/rust/walkdir/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.toml":"82f8a860714a7952156e2ec02f06745707fe43b36e193c4afe91ca30b0b926db","LICENSE-MIT":"0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f","README.md":"dd77cc3c4d98dc80ef9ad75a7779bf8ae85423c3463a64297fa54d14b715d967","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","compare/nftw.c":"6b900b0ac78ce8ece1995f834b194fa14d87d744cabba8f475f0e10b21722c56","compare/walk.py":"d49e26d0b8b2b201d00f2f46bf1f9db46f873c27332da679c9a7adbbf54462d2","rustfmt.toml":"1ca600239a27401c4a43f363cf3f38183a212affc1f31bff3ae93234bbaec228","src/dent.rs":"99226b37127b0a18cf8541b0262fb43b1be52e61b5ae5c574499d316185c5f0d","src/error.rs":"55e9688cc5483eb04b7c765dc8414f51b6342c25264fc3ec248bd7023fa1d93e","src/lib.rs":"9ec13ad047071406c877c03563e621942021725c5d60f50910ce41d6482527e3","src/tests/mod.rs":"bbce9174bfdbb4a81a9000f702be056b63b439cb8f1bcac64b8569368627d56d","src/tests/recursive.rs":"6737833a87e426b4f0b348c176e29af03aa7ade430e6401f14ef010c78e18461","src/tests/util.rs":"ca72ef96f82bb87d8c93d13d581ebb65efcd53fffa87097a84437acecbc30faa","src/util.rs":"14e0da711cad4825ead21446cd61a1444fd49bab853a8a239d8cb74b2caab351"},"package":"777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"} \ No newline at end of file +{"files":{"COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.toml":"421e6948e2f34af6a8392512de0faaac8837b899b0e31df76ee45ca6f2246659","LICENSE-MIT":"0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f","README.md":"5fc28c8211fe74af2889a2eb859127f8d543e0f94be80659c307105ed831f84b","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","compare/nftw.c":"6b900b0ac78ce8ece1995f834b194fa14d87d744cabba8f475f0e10b21722c56","compare/walk.py":"d49e26d0b8b2b201d00f2f46bf1f9db46f873c27332da679c9a7adbbf54462d2","rustfmt.toml":"1ca600239a27401c4a43f363cf3f38183a212affc1f31bff3ae93234bbaec228","src/dent.rs":"99226b37127b0a18cf8541b0262fb43b1be52e61b5ae5c574499d316185c5f0d","src/error.rs":"f197c5c0a1006e622e053cc3c51aaafa8afd5a287fed30f18db59022876d47a0","src/lib.rs":"dca984890839db697b4182043678287370bd08ff766610e5b46091e70ce49591","src/tests/mod.rs":"bbce9174bfdbb4a81a9000f702be056b63b439cb8f1bcac64b8569368627d56d","src/tests/recursive.rs":"1afd9bb86cb04e8fead4d1e075efe00f6e16d7cf17bb3014f8c94e8adf869bea","src/tests/util.rs":"ca72ef96f82bb87d8c93d13d581ebb65efcd53fffa87097a84437acecbc30faa","src/util.rs":"14e0da711cad4825ead21446cd61a1444fd49bab853a8a239d8cb74b2caab351"},"package":"808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"} \ No newline at end of file diff --git a/third_party/rust/walkdir/Cargo.toml b/third_party/rust/walkdir/Cargo.toml index 313d6f4a5a9e..49c666254d55 100644 --- a/third_party/rust/walkdir/Cargo.toml +++ b/third_party/rust/walkdir/Cargo.toml @@ -13,7 +13,7 @@ [package] edition = "2018" name = "walkdir" -version = "2.3.1" +version = "2.3.2" authors = ["Andrew Gallant "] exclude = ["/ci/*", "/.travis.yml", "/appveyor.yml"] description = "Recursively walk a directory." diff --git a/third_party/rust/walkdir/README.md b/third_party/rust/walkdir/README.md index 2b495061f350..14bd4a9d26a4 100644 --- a/third_party/rust/walkdir/README.md +++ b/third_party/rust/walkdir/README.md @@ -6,9 +6,9 @@ open file descriptors and efficient mechanisms for pruning the entries in the directory tree. [![Build status](https://github.com/BurntSushi/walkdir/workflows/ci/badge.svg)](https://github.com/BurntSushi/walkdir/actions) -[![](http://meritbadge.herokuapp.com/walkdir)](https://crates.io/crates/walkdir) +[![](https://meritbadge.herokuapp.com/walkdir)](https://crates.io/crates/walkdir) -Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org). +Dual-licensed under MIT or the [UNLICENSE](https://unlicense.org/). ### Documentation diff --git a/third_party/rust/walkdir/src/error.rs b/third_party/rust/walkdir/src/error.rs index 3fb619c7c21f..9e25a075ec04 100644 --- a/third_party/rust/walkdir/src/error.rs +++ b/third_party/rust/walkdir/src/error.rs @@ -98,7 +98,7 @@ impl Error { /// /// # Example /// - /// ```rust,no-run + /// ```rust,no_run /// use std::io; /// use std::path::Path; /// diff --git a/third_party/rust/walkdir/src/lib.rs b/third_party/rust/walkdir/src/lib.rs index 5132dd57b6ca..929c5655e464 100644 --- a/third_party/rust/walkdir/src/lib.rs +++ b/third_party/rust/walkdir/src/lib.rs @@ -106,7 +106,7 @@ for entry in walker.filter_entry(|e| !is_hidden(e)) { #![deny(missing_docs)] #![allow(unknown_lints)] -#[cfg(test)] +#[cfg(doctest)] doc_comment::doctest!("../README.md"); use std::cmp::{min, Ordering}; @@ -377,13 +377,14 @@ impl WalkDir { self } - /// Set a function for sorting directory entries. + /// Set a function for sorting directory entries with a comparator + /// function. /// /// If a compare function is set, the resulting iterator will return all /// paths in sorted order. The compare function will be called to compare /// entries from the same directory. /// - /// ```rust,no-run + /// ```rust,no_run /// use std::cmp; /// use std::ffi::OsString; /// use walkdir::WalkDir; @@ -398,6 +399,41 @@ impl WalkDir { self } + /// Set a function for sorting directory entries with a key extraction + /// function. + /// + /// If a compare function is set, the resulting iterator will return all + /// paths in sorted order. The compare function will be called to compare + /// entries from the same directory. + /// + /// ```rust,no_run + /// use std::cmp; + /// use std::ffi::OsString; + /// use walkdir::WalkDir; + /// + /// WalkDir::new("foo").sort_by_key(|a| a.file_name().to_owned()); + /// ``` + pub fn sort_by_key(self, mut cmp: F) -> Self + where + F: FnMut(&DirEntry) -> K + Send + Sync + 'static, + K: Ord, + { + self.sort_by(move |a, b| cmp(a).cmp(&cmp(b))) + } + + /// Sort directory entries by file name, to ensure a deterministic order. + /// + /// This is a convenience function for calling `Self::sort_by()`. + /// + /// ```rust,no_run + /// use walkdir::WalkDir; + /// + /// WalkDir::new("foo").sort_by_file_name(); + /// ``` + pub fn sort_by_file_name(self) -> Self { + self.sort_by(|a, b| a.file_name().cmp(b.file_name())) + } + /// Yield a directory's contents before the directory itself. By default, /// this is disabled. /// diff --git a/third_party/rust/walkdir/src/tests/recursive.rs b/third_party/rust/walkdir/src/tests/recursive.rs index bbb1ce114094..4119f461d31f 100644 --- a/third_party/rust/walkdir/src/tests/recursive.rs +++ b/third_party/rust/walkdir/src/tests/recursive.rs @@ -879,7 +879,7 @@ fn filter_entry() { } #[test] -fn sort() { +fn sort_by() { let dir = Dir::tmp(); dir.mkdirp("foo/bar/baz/abc"); dir.mkdirp("quux"); @@ -900,6 +900,49 @@ fn sort() { assert_eq!(expected, r.paths()); } +#[test] +fn sort_by_key() { + let dir = Dir::tmp(); + dir.mkdirp("foo/bar/baz/abc"); + dir.mkdirp("quux"); + + let wd = + WalkDir::new(dir.path()).sort_by_key(|a| a.file_name().to_owned()); + let r = dir.run_recursive(wd); + r.assert_no_errors(); + + let expected = vec![ + dir.path().to_path_buf(), + dir.join("foo"), + dir.join("foo").join("bar"), + dir.join("foo").join("bar").join("baz"), + dir.join("foo").join("bar").join("baz").join("abc"), + dir.join("quux"), + ]; + assert_eq!(expected, r.paths()); +} + +#[test] +fn sort_by_file_name() { + let dir = Dir::tmp(); + dir.mkdirp("foo/bar/baz/abc"); + dir.mkdirp("quux"); + + let wd = WalkDir::new(dir.path()).sort_by_file_name(); + let r = dir.run_recursive(wd); + r.assert_no_errors(); + + let expected = vec![ + dir.path().to_path_buf(), + dir.join("foo"), + dir.join("foo").join("bar"), + dir.join("foo").join("bar").join("baz"), + dir.join("foo").join("bar").join("baz").join("abc"), + dir.join("quux"), + ]; + assert_eq!(expected, r.paths()); +} + #[test] fn sort_max_open() { let dir = Dir::tmp();