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
20 changes: 17 additions & 3 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@ use indicatif::{ProgressBar, ProgressStyle};
use sha2::{Digest, Sha256};
use std::{io::Write, path::Path};

/// Number of retries (after the initial attempt) for transient HTTP failures.
const MAX_RETRIES: u32 = 5;
/// Default number of retries (after the initial attempt) for transient HTTP
/// failures, used when `FOUNDRYUP_MAX_RETRIES` is unset or unparsable.
const DEFAULT_MAX_RETRIES: u32 = 5;

/// Number of retries for transient HTTP failures, honoring the
/// `FOUNDRYUP_MAX_RETRIES` environment variable (matching the install script).
///
/// The script's `FOUNDRYUP_RETRY_DELAY` / `FOUNDRYUP_RETRY_MAX_TIME` are not
/// supported here: reqwest's retry layer manages its own backoff and does not
/// expose delay or total-time knobs.
fn max_retries() -> u32 {
Comment thread
stevencartavia marked this conversation as resolved.
std::env::var("FOUNDRYUP_MAX_RETRIES")
.ok()
.and_then(|v| v.trim().parse().ok())
.unwrap_or(DEFAULT_MAX_RETRIES)
}

/// Transient HTTP statuses that may recover on retry (e.g. GitHub rate limiting
/// or temporary outages). Other errors (e.g. 404) are treated as permanent.
Expand Down Expand Up @@ -56,7 +70,7 @@ impl Downloader {
// otherwise block retries on a CLI that issues only a few requests.
let retry = reqwest::retry::for_host(GitHubHosts)
.no_budget()
.max_retries_per_request(MAX_RETRIES)
.max_retries_per_request(max_retries())
.classify_fn(|req_rep| {
if req_rep.error().is_some() || req_rep.status().is_some_and(is_retryable_status) {
req_rep.retryable()
Expand Down
14 changes: 7 additions & 7 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
config::Config,
download::{Downloader, compute_sha256, extract_tar_gz, extract_zip},
platform::{Platform, Target},
say, warn,
say, tell, warn,
};
use eyre::{Result, WrapErr, bail};
use fs_err as fs;
Expand Down Expand Up @@ -549,18 +549,18 @@ pub(crate) fn list(config: &Config) -> Result<()> {
let version_name = version_entry.file_name();
let version_name = version_name.to_string_lossy();

say!("{owner_name}/{repo_name} {version_name}");
tell!("{owner_name}/{repo_name} {version_name}");

for bin in bins {
let bin_path = version_path.join(bin_name(bin));
if bin_path.exists() {
match get_bin_version(&bin_path) {
Ok(v) => say!("- {v}"),
Err(_) => say!("- {bin} (unknown version)"),
Ok(v) => tell!("- {v}"),
Err(_) => tell!("- {bin} (unknown version)"),
}
}
}
eprintln!();
println!();
}
}
}
Expand All @@ -569,8 +569,8 @@ pub(crate) fn list(config: &Config) -> Result<()> {
let bin_path = config.bin_path(bin);
if bin_path.exists() {
match get_bin_version(&bin_path) {
Ok(v) => say!("- {v}"),
Err(_) => say!("- {bin} (unknown version)"),
Ok(v) => tell!("- {v}"),
Err(_) => tell!("- {bin} (unknown version)"),
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ macro_rules! say {
};
}

/// Like [`say`], but writes to stdout instead of stderr.
#[macro_export]
macro_rules! tell {
($($arg:tt)*) => {
println!("foundryup: {}", format_args!($($arg)*))
};
}

#[macro_export]
macro_rules! warn {
($($arg:tt)*) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/it/foundry_bins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn test_install(version: &str) {

run_forge_test(&foundry_dir, temp_dir.path());

foundryup().env("FOUNDRY_DIR", &foundry_dir).arg("--list").assert().success().stderr_eq(str![
foundryup().env("FOUNDRY_DIR", &foundry_dir).arg("--list").assert().success().stdout_eq(str![
[r#"
foundryup: foundry-rs/foundry [..]
foundryup: - forge [..]
Expand Down
20 changes: 20 additions & 0 deletions tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,26 @@ fn list_empty() {
.success();
}

// `--list` results are written to stdout.
#[test]
fn list_writes_to_stdout() {
let temp_dir = tempfile::Builder::new().tempdir().unwrap();
let foundry_dir = temp_dir.path().join(".foundry");
let version_dir = foundry_dir.join("versions/foundry-rs/foundry/v1.0.0");
std::fs::create_dir_all(&version_dir).unwrap();

for bin in BINS {
std::fs::write(version_dir.join(format!("{bin}{EXE_SUFFIX}")), "fake binary").unwrap();
}

foundryup().env("FOUNDRY_DIR", &foundry_dir).arg("--list").assert().success().stdout_eq(str![
[r#"
foundryup: foundry-rs/foundry v1.0.0
...
"#]
]);
}

#[test]
fn migrate_legacy_versions() {
let temp_dir = tempfile::Builder::new().tempdir().unwrap();
Expand Down