Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ fslock = "0.2.1"
glob = "0.3"
globset = "0.4"
heck = "0.5"
humantime = "2"
indenter = "0.3"
indexmap = { version = "2", features = ["serde"] }
indicatif = { version = "0.17", features = ["default", "improved_unicode"] }
Expand Down Expand Up @@ -151,6 +150,7 @@ xz2 = "0.1"
zip = { version = "2", default-features = false, features = ["deflate"] }
zstd = "0.13"
gix = { version = "<1", features = ["worktree-mutation"] }
jiff = "0.2"

[target.'cfg(unix)'.dependencies]
exec = "0.3"
Expand Down
1 change: 0 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ feature-depth = 1
ignore = [
{ id = "RUSTSEC-2024-0370", reason = "subdependency cannot be updated" },
{ id = "RUSTSEC-2024-0436", reason = "subdependency cannot be updated" },
{ id = "RUSTSEC-2025-0014", reason = "humantime is unmaintained" },
#"RUSTSEC-0000-0000",
#{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" },
#"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish
Expand Down
4 changes: 2 additions & 2 deletions src/cli/settings/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use eyre::{Result, bail, eyre};
use toml_edit::DocumentMut;

use crate::config::settings::{SETTINGS_META, SettingsFile, SettingsType};
use crate::{config, file};
use crate::{config, duration, file};

/// Add/update a setting
///
Expand Down Expand Up @@ -107,7 +107,7 @@ fn parse_i64(value: &str) -> Result<toml_edit::Value> {
}

fn parse_duration(value: &str) -> Result<toml_edit::Value> {
humantime::parse_duration(value)?;
duration::parse_duration(value)?;
Ok(value.into())
}

Expand Down
15 changes: 9 additions & 6 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::cli::Cli;
use crate::config::ALL_TOML_CONFIG_FILES;
use crate::duration;
use crate::file::FindUp;
use crate::{dirs, env, file};
#[allow(unused_imports)]
Expand Down Expand Up @@ -364,14 +365,12 @@ impl Settings {
}

pub fn cache_prune_age_duration(&self) -> Option<Duration> {
if self.cache_prune_age == "0" {
return None;
}
Some(humantime::parse_duration(&self.cache_prune_age).unwrap())
let age = duration::parse_duration(&self.cache_prune_age).unwrap();
if age.as_secs() == 0 { None } else { Some(age) }
}

pub fn fetch_remote_versions_timeout(&self) -> Duration {
humantime::parse_duration(&self.fetch_remote_versions_timeout).unwrap()
duration::parse_duration(&self.fetch_remote_versions_timeout).unwrap()
}

/// duration that remote version cache is kept for
Expand All @@ -383,10 +382,14 @@ impl Settings {
if *env::PREFER_STALE {
None
} else {
Some(humantime::parse_duration(&self.fetch_remote_versions_cache).unwrap())
Some(duration::parse_duration(&self.fetch_remote_versions_cache).unwrap())
}
}

pub fn http_timeout(&self) -> Duration {
duration::parse_duration(&self.http_timeout).unwrap()
}

pub fn log_level(&self) -> log::LevelFilter {
self.log_level.parse().unwrap_or(log::LevelFilter::Info)
}
Expand Down
17 changes: 17 additions & 0 deletions src/duration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
pub use std::time::Duration;

use eyre::{Result, bail};
use jiff::{Span, civil::date};

pub const HOURLY: Duration = Duration::from_secs(60 * 60);
pub const DAILY: Duration = Duration::from_secs(60 * 60 * 24);
pub const WEEKLY: Duration = Duration::from_secs(60 * 60 * 24 * 7);

pub fn parse_duration(s: &str) -> Result<Duration> {
match s.parse::<Span>() {
Ok(span) => {
// we must provide a relative date to determine the duration with months and years
let duration = span.to_duration(date(2025, 1, 1))?;
if duration.is_negative() {
bail!("duration must not be negative: {}", s);
}
Ok(duration.unsigned_abs())
}
Err(_) => Ok(Duration::from_secs(s.parse()?)),
}
}
14 changes: 4 additions & 10 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ use crate::{env, file};
pub static HTTP_VERSION_CHECK: Lazy<Client> =
Lazy::new(|| Client::new(Duration::from_secs(3)).unwrap());

pub static HTTP: Lazy<Client> = Lazy::new(|| {
let duration = humantime::parse_duration(&SETTINGS.http_timeout)
.unwrap_or_else(|_| Duration::from_secs(SETTINGS.http_timeout.parse().unwrap()));
Client::new(duration).unwrap()
});

pub static HTTP_FETCH: Lazy<Client> = Lazy::new(|| {
Client::new(humantime::parse_duration(&SETTINGS.fetch_remote_versions_timeout).unwrap())
.unwrap()
});
pub static HTTP: Lazy<Client> = Lazy::new(|| Client::new(SETTINGS.http_timeout()).unwrap());

pub static HTTP_FETCH: Lazy<Client> =
Lazy::new(|| Client::new(SETTINGS.fetch_remote_versions_timeout()).unwrap());

#[derive(Debug)]
pub struct Client {
Expand Down
13 changes: 7 additions & 6 deletions src/tera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use versions::{Requirement, Versioning};
use crate::cache::CacheManagerBuilder;
use crate::cmd::cmd;
use crate::env_diff::EnvMap;
use crate::{dirs, env, hash};
use crate::{dirs, duration, env, hash};

pub static BASE_CONTEXT: Lazy<Context> = Lazy::new(|| {
let mut context = Context::new();
Expand Down Expand Up @@ -314,11 +314,12 @@ pub fn tera_exec(
_ => return Err("exec cache_key must be a string".into()),
};
let cache_duration = match args.get("cache_duration") {
Some(Value::String(duration)) => match humantime::parse_duration(&duration.to_string())
{
Ok(duration) => Some(duration),
Err(e) => return Err(format!("exec cache_duration: {}", e).into()),
},
Some(Value::String(duration)) => {
match duration::parse_duration(&duration.to_string()) {
Ok(duration) => Some(duration),
Err(e) => return Err(format!("exec cache_duration: {}", e).into()),
}
}
None => None,
_ => return Err("exec cache_duration must be an integer".into()),
};
Expand Down