aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2021-04-02 20:04:29 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-04-02 20:04:29 +0000
commitd947e76f0184deee40088825811f5d003f7d3b8c (patch)
tree96e25337c7fa5779459e6923eace69c0d4199ca8
parenteee15f0ee6a51923a3c55aed27891dc600aa3941 (diff)
parentbe8e0baceed5c92986d7c8dc6583520a977a74ff (diff)
downloadwalkdir-d947e76f0184deee40088825811f5d003f7d3b8c.tar.gz
Upgrade rust/crates/walkdir to 2.3.2 am: be8e0baceeandroid-s-beta-4android-s-beta-3android-s-beta-4
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/walkdir/+/1662263 Change-Id: Ic099d717886735bfa2cacc422b543951e2f6644e
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.github/workflows/ci.yml1
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--LICENSE-MIT21
-rw-r--r--METADATA10
-rw-r--r--README.md4
-rw-r--r--UNLICENSE24
-rw-r--r--src/error.rs2
-rw-r--r--src/lib.rs42
-rw-r--r--src/tests/recursive.rs45
11 files changed, 140 insertions, 15 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 95abad6..430f9d6 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
{
"git": {
- "sha1": "00df609016d7e75b3730fcf0cef25fc0efe14204"
+ "sha1": "abf3a15887758e0af54ebca827c7b6f8b311cb45"
}
}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b284608..fc6824a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -55,6 +55,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
+ override: true
profile: minimal
- run: cargo build --verbose
- run: cargo doc --verbose
diff --git a/Cargo.toml b/Cargo.toml
index 313d6f4..49c6662 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "walkdir"
-version = "2.3.1"
+version = "2.3.2"
authors = ["Andrew Gallant <jamslam@gmail.com>"]
exclude = ["/ci/*", "/.travis.yml", "/appveyor.yml"]
description = "Recursively walk a directory."
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 94fc562..c71c2fe 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "walkdir"
-version = "2.3.1" #:version
+version = "2.3.2" #:version
authors = ["Andrew Gallant <jamslam@gmail.com>"]
description = "Recursively walk a directory."
documentation = "https://docs.rs/walkdir/"
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644
index 0000000..3b0a5dc
--- /dev/null
+++ b/LICENSE-MIT
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Andrew Gallant
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/METADATA b/METADATA
index c49f861..42088b4 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/walkdir/walkdir-2.3.1.crate"
+ value: "https://static.crates.io/crates/walkdir/walkdir-2.3.2.crate"
}
- version: "2.3.1"
+ version: "2.3.2"
license_type: NOTICE
last_upgrade_date {
- year: 2020
- month: 12
- day: 21
+ year: 2021
+ month: 4
+ day: 2
}
}
diff --git a/README.md b/README.md
index 2b49506..14bd4a9 100644
--- a/README.md
+++ b/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/UNLICENSE b/UNLICENSE
new file mode 100644
index 0000000..68a49da
--- /dev/null
+++ b/UNLICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
diff --git a/src/error.rs b/src/error.rs
index 3fb619c..9e25a07 100644
--- a/src/error.rs
+++ b/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/src/lib.rs b/src/lib.rs
index 5132dd5..929c565 100644
--- a/src/lib.rs
+++ b/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<K, F>(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/src/tests/recursive.rs b/src/tests/recursive.rs
index bbb1ce1..4119f46 100644
--- a/src/tests/recursive.rs
+++ b/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");
@@ -901,6 +901,49 @@ fn sort() {
}
#[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();
dir.mkdirp("foo/bar/baz/abc");