From bd64408e8b05a6b366b0cf8a383a49956f8375c3 Mon Sep 17 00:00:00 2001 From: Adam Dickinson Date: Sat, 15 Jun 2024 22:17:58 +1000 Subject: [PATCH] fix: allow glob patterns in task outputs and sources (#2285) (#2286) --- Cargo.lock | 8 +++++++- Cargo.toml | 2 +- src/cli/run.rs | 26 +++++++++++++++++++------- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5643b1a9f..7a971b7e15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1076,6 +1076,12 @@ dependencies = [ "url", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "globset" version = "0.4.14" @@ -1788,8 +1794,8 @@ dependencies = [ "flate2", "fslock", "git2", + "glob", "globset", - "globwalk", "heck 0.5.0", "home", "humantime", diff --git a/Cargo.toml b/Cargo.toml index a08fc0745c..5dddb531e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,8 +63,8 @@ filetime = "0.2.23" flate2 = "1.0.30" fslock = "0.2.1" git2 = "0.18.3" +glob = "0.3.1" globset = "0.4.14" -globwalk = "0.9.1" heck = "0.5" home = "0.5.9" humantime = "2.1.0" diff --git a/src/cli/run.rs b/src/cli/run.rs index ab07a443e4..61a5982c5a 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -15,7 +15,7 @@ use demand::{DemandOption, Select}; use duct::IntoExecutablePath; use either::Either; use eyre::{bail, ensure, eyre, Result}; -use globwalk::GlobWalkerBuilder; +use glob::glob; use itertools::Itertools; use once_cell::sync::Lazy; @@ -479,7 +479,7 @@ impl Run { fn is_glob_pattern(path: &str) -> bool { // This is the character set used for glob - // detection by globwalk + // detection by glob let glob_chars = ['*', '{', '}']; path.chars().any(|c| glob_chars.contains(&c)) @@ -512,12 +512,24 @@ fn last_modified_glob_match( if patterns.is_empty() { return Ok(None); } - let files = GlobWalkerBuilder::from_patterns(root, patterns) - .follow_links(true) - .build()? + let files = patterns + .iter() + .flat_map(|pattern| { + glob( + root.as_ref() + .join(pattern) + .to_str() + .expect("Conversion to string path failed"), + ) + .unwrap() + }) .filter_map(|e| e.ok()) - .filter(|e| e.file_type().is_file()) - .map(|e| e.path().to_owned()); + .filter(|e| { + e.metadata() + .expect("Metadata call failed") + .file_type() + .is_file() + }); last_modified_file(files) }