Skip to content

Commit

Permalink
fix: performance fix for _.file/_.path
Browse files Browse the repository at this point in the history
Fixes #2061
  • Loading branch information
jdx committed May 12, 2024
1 parent c70d567 commit 76202de
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
18 changes: 17 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 2 additions & 20 deletions src/config/env_directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;
Expand All @@ -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)? {
Expand All @@ -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() {
Expand Down

0 comments on commit 76202de

Please sign in to comment.