Skip to content

Commit b4670fa

Browse files
Don't use a mutex for downloadable
1 parent 99e6a98 commit b4670fa

File tree

3 files changed

+57
-56
lines changed

3 files changed

+57
-56
lines changed

Cargo.lock

Lines changed: 41 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ clap_complete = "4.5"
5656
parking_lot = "0.12"
5757
serde_json = "1.0"
5858
indicatif = "0.17"
59-
octocrab = "0.42"
59+
octocrab = "0.43"
6060
fs_extra = "1.3"
6161
ferinth = "2.11"
6262
colored = "3.0"
6363
inquire = "0.7"
64-
libium = { git = "https://github.com/gorilla-devs/libium", rev = "713057124a8216d78b7bdba58c67541c6e9a904a" }
64+
libium = { git = "https://github.com/gorilla-devs/libium", rev = "e043a6e17a475158a595cfcf1767ef81521d0587" }
6565
# libium = { path = "../libium" }
6666
# libium = "1.32"
6767
anyhow = "1.0"

src/subcommands/upgrade.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use tokio::task::JoinSet;
2727
/// If an error occurs with a resolving task, instead of failing immediately,
2828
/// resolution will continue and the error return flag is set to true.
2929
pub async fn get_platform_downloadables(profile: &Profile) -> Result<(Vec<DownloadData>, bool)> {
30-
let to_download = Arc::new(Mutex::new(Vec::new()));
3130
let progress_bar = Arc::new(Mutex::new(ProgressBar::new(0).with_style(STYLE_NO.clone())));
3231
let mut tasks = JoinSet::new();
3332
let mut done_mods = Vec::new();
@@ -73,11 +72,10 @@ pub async fn get_platform_downloadables(profile: &Profile) -> Result<(Vec<Downlo
7372

7473
let filters = profile.filters.clone();
7574
let dep_sender = Arc::clone(&mod_sender);
76-
let to_download = Arc::clone(&to_download);
7775
let progress_bar = Arc::clone(&progress_bar);
7876

7977
tasks.spawn(async move {
80-
let permit = SEMAPHORE.get_or_init(default_semaphore).acquire().await?;
78+
let permit = SEMAPHORE.get_or_init(default_semaphore).acquire().await?;
8179

8280
let result = mod_.fetch_download_file(filters).await;
8381

@@ -114,8 +112,7 @@ pub async fn get_platform_downloadables(profile: &Profile) -> Result<(Vec<Downlo
114112
false,
115113
))?;
116114
}
117-
to_download.lock().push(download_file);
118-
Ok(true)
115+
Ok(Some(download_file))
119116
}
120117
Err(err) => {
121118
if let mod_downloadable::Error::ModrinthError(
@@ -130,29 +127,28 @@ pub async fn get_platform_downloadables(profile: &Profile) -> Result<(Vec<Downlo
130127
"{}",
131128
format!("{CROSS} {:pad_len$} {err}", mod_.name).red()
132129
));
133-
Ok(false)
130+
Ok(None)
134131
}
135132
}
136133
});
137134
}
138135
}
139136

140-
let error = tasks
141-
.join_all()
142-
.await
143-
.iter()
144-
.any(|r| matches!(r, Ok(false)));
145-
146137
Arc::try_unwrap(progress_bar)
147138
.map_err(|_| anyhow!("Failed to run threads to completion"))?
148139
.into_inner()
149140
.finish_and_clear();
150-
Ok((
151-
Arc::try_unwrap(to_download)
152-
.map_err(|_| anyhow!("Failed to run threads to completion"))?
153-
.into_inner(),
154-
error,
155-
))
141+
142+
let tasks = tasks
143+
.join_all()
144+
.await
145+
.into_iter()
146+
.collect::<Result<Vec<_>>>()?;
147+
148+
let error = tasks.iter().any(Option::is_none);
149+
let to_download = tasks.into_iter().flatten().collect();
150+
151+
Ok((to_download, error))
156152
}
157153

158154
pub async fn upgrade(profile: &Profile) -> Result<()> {

0 commit comments

Comments
 (0)