MCPcopy Create free account
hub / github.com/archlinux/alpm / parallel_update_or_clone

Method parallel_update_or_clone

dev-scripts/src/sync/pkgsrc.rs:136–175  ·  view source on GitHub ↗

Update/clone all git repositories in parallel with rayon. A progress bar is added for progress indication.

(&self, repos: &[String], download_dir: &Path)

Source from the content-addressed store, hash-verified

134 ///
135 /// A progress bar is added for progress indication.
136 fn parallel_update_or_clone(&self, repos: &[String], download_dir: &Path) -> Result<(), Error> {
137 let progress_bar = get_progress_bar(repos.len() as u64);
138
139 // Prepare a ssh session for better performance.
140 warmup_ssh_session()?;
141
142 // Clone/update all repositories in parallel
143 let results: Vec<Result<(), Error>> = repos
144 .par_iter()
145 .map(|repo| {
146 let target_dir = download_dir.join(repo);
147
148 // If the repo already exists, only pull it.
149 // Otherwise do a clone.
150 let result = if target_dir.exists() {
151 update_repo(repo, &target_dir)
152 } else {
153 clone_repo(repo.to_string(), &target_dir)
154 };
155
156 // Increment the counter
157 progress_bar.inc(1);
158 result
159 })
160 .collect();
161
162 // Finish the spinner
163 progress_bar.finish_with_message("All repositories cloned or updated.");
164
165 // Display any errors during cloning/updating to the user.
166 let mut error_iter = results.into_iter().filter_map(Result::err).peekable();
167 if error_iter.peek().is_some() {
168 error!("The command failed for the following repositories:");
169 for error in error_iter {
170 error!("{error}");
171 }
172 }
173
174 Ok(())
175 }
176}
177
178/// Create a new ssh connection that doesn't get bound to a given session.

Calls 7

get_progress_barFunction · 0.85
warmup_ssh_sessionFunction · 0.85
update_repoFunction · 0.85
clone_repoFunction · 0.85
lenMethod · 0.45
joinMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected