11use std:: {
2- collections:: HashMap ,
32 fs,
43 path:: { Path , PathBuf } ,
5- time:: Duration ,
64} ;
75
86use anyhow:: Context ;
9- use indicatif:: { ProgressBar , ProgressStyle } ;
107use reqwest:: Url ;
118use semver:: Version ;
129
@@ -18,12 +15,14 @@ use crate::{
1815 prelude:: * ,
1916} ;
2017
18+ /// Returns the path to the installed package and a bool indicating
19+ /// if the package was downloaded.
2120pub fn install < S , C > (
2221 pkg : S ,
2322 version : & Version ,
2423 index : Option < & Index > ,
2524 progress_callback : C ,
26- ) -> Result < PathBuf >
25+ ) -> Result < ( PathBuf , bool ) >
2726where
2827 S : AsRef < str > ,
2928 C : FnMut ( git2:: Progress < ' _ > ) ,
5251 let ident = format ! ( "{}-{}" , pkg, version) ;
5352 let path = paths:: pkg ( "." , & ident) ;
5453 if path. exists ( ) {
55- return Ok ( path) ;
54+ return Ok ( ( path, false ) ) ;
5655 }
5756
5857 let ( path, _) = install_git (
6160 Some ( & ident) ,
6261 progress_callback,
6362 ) ?;
64- Ok ( path)
63+
64+ Ok ( ( path, true ) )
6565}
6666
6767/// Returns the path to the installed package and the revision
@@ -217,78 +217,3 @@ pub fn prepare_pkg(path: &Path, ident: Option<&str>) -> Result<()> {
217217
218218 Ok ( ( ) )
219219}
220-
221- pub fn install_multiple < F > (
222- pkgs : & HashMap < String , Version > ,
223- with_progress : bool ,
224- index : Option < & Index > ,
225- on_install : Option < F > ,
226- ) -> Result < HashMap < String , PathBuf > >
227- where
228- F : Fn ( & str , & Version ) ,
229- {
230- let mut owned_index = None ;
231- let index = index. map_or_else (
232- || -> Result < & Index > {
233- owned_index = Some ( index:: parse ( false , false ) ?) ;
234- Ok ( owned_index. as_ref ( ) . unwrap ( ) )
235- } ,
236- |i| Ok ( i) ,
237- ) ?;
238-
239- let mut paths = HashMap :: new ( ) ;
240- if with_progress {
241- let progress = crate :: log:: get_multi_progress ( ) ;
242- let install_progress = progress. add (
243- ProgressBar :: new_spinner ( ) . with_style (
244- ProgressStyle :: default_spinner ( )
245- . template ( "{spinner:>11}> {msg}" ) ?
246- . tick_chars ( "=\\ |/===" ) ,
247- ) ,
248- ) ;
249- let fetch_progress = progress. add (
250- ProgressBar :: new ( pkgs. len ( ) as u64 )
251- . with_style (
252- ProgressStyle :: default_bar ( )
253- . template ( "{prefix:>12.bright.cyan} [{bar:40}] {pos}/{len}" ) ?
254- . progress_chars ( "=> " ) ,
255- )
256- . with_prefix ( "Fetching" ) ,
257- ) ;
258- install_progress. enable_steady_tick ( Duration :: from_millis ( 150 ) ) ;
259- fetch_progress. tick ( ) ;
260-
261- for ( pkg, version) in pkgs. iter ( ) {
262- install_progress. set_message ( format ! ( "{} v{}" , pkg, version) ) ;
263-
264- let path = install ( pkg, version, Some ( index) , |_| { } ) ?;
265- paths. insert ( pkg. clone ( ) , path) ;
266-
267- install_progress. println ( format ! (
268- "{:>12} {} v{}" ,
269- console:: style( "Installed" ) . bright( ) . green( ) ,
270- pkg,
271- version
272- ) ) ;
273- fetch_progress. inc ( 1 ) ;
274-
275- if let Some ( on_install) = & on_install {
276- on_install ( pkg, version) ;
277- }
278- }
279-
280- fetch_progress. finish ( ) ;
281- install_progress. finish_and_clear ( ) ;
282- progress. clear ( ) ?;
283- } else {
284- for ( pkg, version) in pkgs. iter ( ) {
285- let path = install ( pkg, version, Some ( index) , |_| { } ) ?;
286- paths. insert ( pkg. clone ( ) , path) ;
287- if let Some ( on_install) = & on_install {
288- on_install ( pkg, version) ;
289- }
290- }
291- }
292-
293- Ok ( paths)
294- }
0 commit comments