aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2024-02-06 08:09:09 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-02-06 08:09:09 +0000
commit912c828fac3bb1b33bc9435016693c1645c508df (patch)
tree4d32fb5f30e5a3eec95f72b1d706f60151b70732
parentb69210aa355e25a9dc61e84ec321867e8b72439c (diff)
parent147097ccb4fd39e0ae83352ad5828af6a541c10e (diff)
downloadwalkdir-master.tar.gz
Upgrade walkdir to 2.4.0 am: 147097ccb4HEADmastermainemu-34-2-dev
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/walkdir/+/2950808 Change-Id: I1a345952da694a7043ce1c7acbacc81615695527 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.github/workflows/ci.yml16
-rw-r--r--Android.bp2
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA25
-rw-r--r--src/lib.rs27
-rw-r--r--src/tests/recursive.rs71
8 files changed, 119 insertions, 28 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 6fd8d24..ca4d1d5 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "1547668537df06ebc4a708d2048e676e1de4fa91"
+ "sha1": "037c5e16ec4d8b3eacb51f077cfdab7a356e8412"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index fc6824a..8c64a92 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -23,28 +23,28 @@ jobs:
- win-gnu
include:
- build: pinned
- os: ubuntu-18.04
+ os: ubuntu-latest
rust: 1.34.0
- build: pinned-win
- os: windows-2019
+ os: windows-latest
rust: 1.34.0
- build: stable
- os: ubuntu-18.04
+ os: ubuntu-latest
rust: stable
- build: beta
- os: ubuntu-18.04
+ os: ubuntu-latest
rust: beta
- build: nightly
- os: ubuntu-18.04
+ os: ubuntu-latest
rust: nightly
- build: macos
os: macos-latest
rust: stable
- build: win-msvc
- os: windows-2019
+ os: windows-latest
rust: stable
- build: win-gnu
- os: windows-2019
+ os: windows-latest
rust: stable-x86_64-gnu
steps:
- name: Checkout repository
@@ -70,7 +70,7 @@ jobs:
rustfmt:
name: rustfmt
- runs-on: ubuntu-18.04
+ runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v1
diff --git a/Android.bp b/Android.bp
index 6430519..8049964 100644
--- a/Android.bp
+++ b/Android.bp
@@ -42,7 +42,7 @@ rust_library {
host_supported: true,
crate_name: "walkdir",
cargo_env_compat: true,
- cargo_pkg_version: "2.3.3",
+ cargo_pkg_version: "2.4.0",
srcs: ["src/lib.rs"],
edition: "2018",
rustlibs: ["libsame_file"],
diff --git a/Cargo.toml b/Cargo.toml
index 7db9263..4c29a20 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "walkdir"
-version = "2.3.3"
+version = "2.4.0"
authors = ["Andrew Gallant <jamslam@gmail.com>"]
exclude = [
"/ci/*",
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 0f4faa6..c120bd3 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "walkdir"
-version = "2.3.3" #:version
+version = "2.4.0" #:version
authors = ["Andrew Gallant <jamslam@gmail.com>"]
description = "Recursively walk a directory."
documentation = "https://docs.rs/walkdir/"
diff --git a/METADATA b/METADATA
index e37eab0..bdc135f 100644
--- a/METADATA
+++ b/METADATA
@@ -1,23 +1,20 @@
# This project was upgraded with external_updater.
-# Usage: tools/external_updater/updater.sh update rust/crates/walkdir
-# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+# Usage: tools/external_updater/updater.sh update external/rust/crates/walkdir
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
name: "walkdir"
description: "Recursively walk a directory."
third_party {
- url {
- type: HOMEPAGE
- value: "https://crates.io/crates/walkdir"
- }
- url {
- type: ARCHIVE
- value: "https://static.crates.io/crates/walkdir/walkdir-2.3.3.crate"
- }
- version: "2.3.3"
license_type: NOTICE
last_upgrade_date {
- year: 2023
- month: 3
- day: 30
+ year: 2024
+ month: 2
+ day: 5
+ }
+ homepage: "https://crates.io/crates/walkdir"
+ identifier {
+ type: "Archive"
+ value: "https://static.crates.io/crates/walkdir/walkdir-2.4.0.crate"
+ version: "2.4.0"
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 4d41515..edf702e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -237,6 +237,7 @@ pub struct WalkDir {
struct WalkDirOptions {
follow_links: bool,
+ follow_root_links: bool,
max_open: usize,
min_depth: usize,
max_depth: usize,
@@ -265,6 +266,7 @@ impl fmt::Debug for WalkDirOptions {
};
f.debug_struct("WalkDirOptions")
.field("follow_links", &self.follow_links)
+ .field("follow_root_link", &self.follow_root_links)
.field("max_open", &self.max_open)
.field("min_depth", &self.min_depth)
.field("max_depth", &self.max_depth)
@@ -287,6 +289,7 @@ impl WalkDir {
WalkDir {
opts: WalkDirOptions {
follow_links: false,
+ follow_root_links: true,
max_open: 10,
min_depth: 0,
max_depth: ::std::usize::MAX,
@@ -344,6 +347,25 @@ impl WalkDir {
self
}
+ /// Follow symbolic links if these are the root of the traversal.
+ /// By default, this is enabled.
+ ///
+ /// When `yes` is `true`, symbolic links on root paths are followed
+ /// which is effective if the symbolic link points to a directory.
+ /// If a symbolic link is broken or is involved in a loop, an error is yielded
+ /// as the first entry of the traversal.
+ ///
+ /// When enabled, the yielded [`DirEntry`] values represent the target of
+ /// the link while the path corresponds to the link. See the [`DirEntry`]
+ /// type for more details, and all future entries will be contained within
+ /// the resolved directory behind the symbolic link of the root path.
+ ///
+ /// [`DirEntry`]: struct.DirEntry.html
+ pub fn follow_root_links(mut self, yes: bool) -> Self {
+ self.opts.follow_root_links = yes;
+ self
+ }
+
/// Set the maximum number of simultaneously open file descriptors used
/// by the iterator.
///
@@ -830,7 +852,10 @@ impl IntoIter {
} else {
itry!(self.push(&dent));
}
- } else if dent.depth() == 0 && dent.file_type().is_symlink() {
+ } else if dent.depth() == 0
+ && dent.file_type().is_symlink()
+ && self.opts.follow_root_links
+ {
// As a special case, if we are processing a root entry, then we
// always follow it even if it's a symlink and follow_links is
// false. We are careful to not let this change the semantics of
diff --git a/src/tests/recursive.rs b/src/tests/recursive.rs
index 4119f46..e415b91 100644
--- a/src/tests/recursive.rs
+++ b/src/tests/recursive.rs
@@ -383,7 +383,76 @@ fn sym_root_file_follow() {
}
#[test]
-fn sym_root_dir_nofollow() {
+fn broken_sym_root_dir_nofollow_and_root_nofollow() {
+ let dir = Dir::tmp();
+ dir.symlink_dir("broken", "a-link");
+
+ let wd = WalkDir::new(dir.join("a-link"))
+ .follow_links(false)
+ .follow_root_links(false);
+ let r = dir.run_recursive(wd);
+ let ents = r.sorted_ents();
+ assert_eq!(ents.len(), 1);
+ let link = &ents[0];
+ assert_eq!(dir.join("a-link"), link.path());
+ assert!(link.path_is_symlink());
+}
+
+#[test]
+fn broken_sym_root_dir_follow_and_root_nofollow() {
+ let dir = Dir::tmp();
+ dir.symlink_dir("broken", "a-link");
+
+ let wd = WalkDir::new(dir.join("a-link"))
+ .follow_links(true)
+ .follow_root_links(false);
+ let r = dir.run_recursive(wd);
+ assert!(r.sorted_ents().is_empty());
+ assert_eq!(
+ r.errs().len(),
+ 1,
+ "broken symlink cannot be traversed - they are followed if symlinks are followed"
+ );
+}
+
+#[test]
+fn broken_sym_root_dir_root_is_always_followed() {
+ let dir = Dir::tmp();
+ dir.symlink_dir("broken", "a-link");
+
+ for follow_symlinks in &[true, false] {
+ let wd =
+ WalkDir::new(dir.join("a-link")).follow_links(*follow_symlinks);
+ let r = dir.run_recursive(wd);
+ assert!(r.sorted_ents().is_empty());
+ assert_eq!(
+ r.errs().len(),
+ 1,
+ "broken symlink in roots cannot be traversed, they are always followed"
+ );
+ }
+}
+
+#[test]
+fn sym_root_dir_nofollow_root_nofollow() {
+ let dir = Dir::tmp();
+ dir.mkdirp("a");
+ dir.symlink_dir("a", "a-link");
+ dir.touch("a/zzz");
+
+ let wd = WalkDir::new(dir.join("a-link")).follow_root_links(false);
+ let r = dir.run_recursive(wd);
+ r.assert_no_errors();
+
+ let ents = r.sorted_ents();
+ assert_eq!(1, ents.len());
+ let link = &ents[0];
+ assert_eq!(dir.join("a-link"), link.path());
+ assert_eq!(0, link.depth());
+}
+
+#[test]
+fn sym_root_dir_nofollow_root_follow() {
let dir = Dir::tmp();
dir.mkdirp("a");
dir.symlink_dir("a", "a-link");