Skip to content

Commit 5f22afb

Browse files
committed
Use configured libc, allow force reinstall
1 parent 57dcc71 commit 5f22afb

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

src/command/update.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ pub struct UpdateInstalled {
1818
check: bool,
1919
/// The JDK to update. Version key, 'all', or 'default'.
2020
target: UpdateTarget,
21+
/// Force update even if the version is the same.
22+
#[clap(short, long)]
23+
force: bool,
2124
}
2225

2326
#[derive(Debug, Clone)]
@@ -95,19 +98,24 @@ impl JpreCommand for UpdateInstalled {
9598
}
9699
};
97100
let latest = list_info.java_version;
98-
if latest.compare(&full_version) == std::cmp::Ordering::Greater {
101+
let do_update = if latest.compare(&full_version) == std::cmp::Ordering::Greater {
99102
eprintln!(
100103
" New version available: {}",
101104
latest.if_supports_color(Stream::Stderr, |s| s.color(jdk_color()))
102105
);
103-
if !self.check {
104-
Self::update_jdk(&context, &jdk)?;
105-
}
106+
true
106107
} else {
107108
eprintln!(
108109
" Already up-to-date: {}",
109110
full_version.if_supports_color(Stream::Stderr, |s| s.color(jdk_color()))
110111
);
112+
if self.force {
113+
eprintln!(" Forcing re-install...");
114+
}
115+
self.force
116+
};
117+
if do_update && !self.check {
118+
Self::update_jdk(&context, &jdk)?;
111119
}
112120
} else {
113121
warn!("No full version found for {}", jdk);

src/config.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ pub struct JpreConfig {
3535
/// mapped.
3636
#[serde(default)]
3737
pub forced_os: Option<String>,
38+
/// libc to force when downloading a JDK. If not set, "glibc" will be used.
39+
/// This is only relevant on Linux.
40+
#[serde(default = "default_libc")]
41+
pub forced_libc: String,
42+
}
43+
44+
fn default_distribution() -> Vec<String> {
45+
vec!["temurin".to_string()]
46+
}
47+
48+
fn default_libc() -> String {
49+
"glibc".to_string()
3850
}
3951

4052
impl JpreConfig {
@@ -149,7 +161,3 @@ impl JpreConfig {
149161
Ok(())
150162
}
151163
}
152-
153-
fn default_distribution() -> Vec<String> {
154-
vec!["temurin".to_string()]
155-
}

src/foojay.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ fn detected_foojay_arch() -> &'static str {
3939
}
4040
}
4141

42-
fn detected_foojay_os() -> &'static str {
42+
fn detected_foojay_os(libc: &str) -> &'static str {
4343
match std::env::consts::OS {
4444
"macos" => "macos",
4545
"linux" => {
46-
if cfg!(target_env = "musl") {
46+
if libc == "musl" {
4747
"linux-musl"
4848
} else {
4949
"linux"
@@ -139,10 +139,11 @@ impl FoojayDiscoApi {
139139
.forced_architecture
140140
.clone()
141141
.unwrap_or_else(|| detected_foojay_arch().to_string());
142+
let libc = config.forced_libc.clone();
142143
let os = config
143144
.forced_os
144145
.clone()
145-
.unwrap_or_else(|| detected_foojay_os().to_string());
146+
.unwrap_or_else(|| detected_foojay_os(&libc).to_string());
146147
let url = Url::parse_with_params(
147148
&format!("{}/packages", FOOJAY_BASE_URL),
148149
&[
@@ -164,6 +165,7 @@ impl FoojayDiscoApi {
164165
("distribution", distribution.to_string()),
165166
("operating_system", os),
166167
("architecture", arch),
168+
("libc_type", libc.clone()),
167169
],
168170
)
169171
.unwrap();

0 commit comments

Comments
 (0)