From 76202ded1bb47ecf9c1a5a7e6f71216aca26c68e Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Sun, 12 May 2024 10:33:55 -0500 Subject: [PATCH] fix: performance fix for _.file/_.path Fixes #2061 --- Cargo.lock | 18 +++++++++++++++++- Cargo.toml | 1 + src/config/env_directive.rs | 22 ++-------------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30c7d3286..09510536b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1550,6 +1550,7 @@ dependencies = [ "versions", "walkdir", "which", + "xx 0.5.1", "zip", ] @@ -3035,7 +3036,7 @@ dependencies = [ "shell-escape", "strum", "thiserror", - "xx", + "xx 0.2.5", ] [[package]] @@ -3449,6 +3450,21 @@ dependencies = [ "thiserror", ] +[[package]] +name = "xx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e56d3f594fa196a364c0fdd4bab4b4e81fe46712c6754c9bc0930a6eac6998d" +dependencies = [ + "duct", + "filetime", + "globwalk 0.9.1", + "log", + "miette", + "regex", + "thiserror", +] + [[package]] name = "yansi" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 1076bcac4..b31ec584c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,6 +108,7 @@ usage-lib = { version = "0.1.18", features = ["clap"] } versions = { version = "6.2.0", features = ["serde"] } walkdir = "2.5.0" which = "6.0.1" +xx = { version = "0.5.0", features = ["glob"] } zip = { version = "1.1.2", default-features = false, features = ["deflate"] } [target.'cfg(unix)'.dependencies] diff --git a/src/config/env_directive.rs b/src/config/env_directive.rs index fbca1caa2..435495924 100644 --- a/src/config/env_directive.rs +++ b/src/config/env_directive.rs @@ -3,7 +3,6 @@ use std::fmt::Display; use std::path::{Path, PathBuf}; use eyre::Context; -use globwalk::{GlobError, GlobWalkerBuilder}; use indexmap::IndexMap; use crate::cmd::CmdLineRunner; @@ -111,23 +110,6 @@ impl EnvResults { _ => p.to_path_buf(), } }; - let glob_files = |path: PathBuf| { - // Use the longuest path without any glob pattern character as root - let root = path - .ancestors() - .skip(1) - .find(|a| !"*[{?".chars().any(|c| a.to_str().unwrap().contains(c))) - .unwrap() - .to_path_buf(); - let pattern = path.strip_prefix(&root).unwrap(); - let files = GlobWalkerBuilder::new(root, pattern.to_string_lossy()) - .follow_links(true) - .build()? - .filter_map(|e| e.ok()) - .filter(|e| e.file_type().is_file()) - .map(|e| e.into_path()); - Ok::<_, GlobError>(files) - }; match directive { EnvDirective::Val(k, v) => { let v = r.parse_template(&ctx, &source, &v)?; @@ -147,7 +129,7 @@ impl EnvResults { EnvDirective::File(input) => { trust_check(&source)?; let s = r.parse_template(&ctx, &source, input.to_string_lossy().as_ref())?; - for p in glob_files(normalize_path(s.into()))? { + for p in xx::file::glob(normalize_path(s.into()))? { r.env_files.push(p.clone()); let errfn = || eyre!("failed to parse dotenv file: {}", display_path(&p)); for item in dotenvy::from_path_iter(&p).wrap_err_with(errfn)? { @@ -161,7 +143,7 @@ impl EnvResults { settings.ensure_experimental("env._.source")?; trust_check(&source)?; let s = r.parse_template(&ctx, &source, input.to_string_lossy().as_ref())?; - for p in glob_files(normalize_path(s.into()))? { + for p in xx::file::glob(normalize_path(s.into()))? { r.env_scripts.push(p.clone()); let env_diff = EnvDiff::from_bash_script(&p, env_vars.clone())?; for p in env_diff.to_patches() {