@@ -4,7 +4,6 @@ use crates_io::storage::Storage;
44use crates_io:: tasks:: spawn_blocking;
55use crates_io_index:: { Repository , RepositoryConfig } ;
66use indicatif:: { ProgressBar , ProgressIterator , ProgressStyle } ;
7- use tokio:: runtime:: Handle ;
87
98#[ derive( clap:: Parser , Debug ) ]
109#[ command(
@@ -17,52 +16,55 @@ pub struct Opts {
1716}
1817
1918pub async fn run ( opts : Opts ) -> anyhow:: Result < ( ) > {
20- spawn_blocking ( move || {
21- let storage = Storage :: from_environment ( ) ;
19+ let storage = Storage :: from_environment ( ) ;
2220
23- println ! ( "fetching git repo" ) ;
24- let config = RepositoryConfig :: from_environment ( ) ?;
21+ println ! ( "fetching git repo" ) ;
22+ let config = RepositoryConfig :: from_environment ( ) ?;
23+ let ( repo, files) = spawn_blocking ( move || {
2524 let repo = Repository :: open ( & config) ?;
2625 repo. reset_head ( ) ?;
2726 println ! ( "HEAD is at {}" , repo. head_oid( ) ?) ;
2827
2928 let files = repo. get_files_modified_since ( opts. incremental_commit . as_deref ( ) ) ?;
3029 println ! ( "found {} files to upload" , files. len( ) ) ;
31- if !dialoguer:: confirm ( "continue with upload?" ) ? {
32- return Ok ( ( ) ) ;
33- }
3430
35- let pb = ProgressBar :: new ( files. len ( ) as u64 ) ;
36- pb. set_style ( ProgressStyle :: with_template (
37- "{bar:60} ({pos}/{len}, ETA {eta})" ,
38- ) ?) ;
31+ Ok :: < _ , anyhow:: Error > ( ( repo, files) )
32+ } )
33+ . await ?;
34+
35+ if !dialoguer:: async_confirm ( "continue with upload?" ) . await ? {
36+ return Ok ( ( ) ) ;
37+ }
3938
40- for file in files. iter ( ) . progress_with ( pb. clone ( ) ) {
41- let file_name = file. file_name ( ) . ok_or_else ( || {
42- let file = file. display ( ) ;
43- anyhow ! ( "Failed to get file name from path: {file}" )
44- } ) ?;
39+ let pb = ProgressBar :: new ( files. len ( ) as u64 ) ;
40+ pb. set_style ( ProgressStyle :: with_template (
41+ "{bar:60} ({pos}/{len}, ETA {eta})" ,
42+ ) ?) ;
4543
46- let crate_name = file_name. to_str ( ) . ok_or_else ( || {
47- let file_name = file_name. to_string_lossy ( ) ;
48- anyhow ! ( "Failed to convert file name to utf8: {file_name}" , )
49- } ) ?;
44+ for file in files. iter ( ) . progress_with ( pb. clone ( ) ) {
45+ let file_name = file. file_name ( ) . ok_or_else ( || {
46+ let file = file. display ( ) ;
47+ anyhow ! ( "Failed to get file name from path: {file}" )
48+ } ) ?;
5049
51- let path = repo. index_file ( crate_name) ;
52- if !path. exists ( ) {
53- pb. suspend ( || println ! ( "skipping file `{crate_name}`" ) ) ;
54- continue ;
55- }
50+ let crate_name = file_name. to_str ( ) . ok_or_else ( || {
51+ let file_name = file_name. to_string_lossy ( ) ;
52+ anyhow ! ( "Failed to convert file name to utf8: {file_name}" , )
53+ } ) ?;
5654
57- let contents = std:: fs:: read_to_string ( & path) ?;
58- Handle :: current ( ) . block_on ( storage. sync_index ( crate_name, Some ( contents) ) ) ?;
55+ let path = repo. index_file ( crate_name) ;
56+ if !path. exists ( ) {
57+ pb. suspend ( || println ! ( "skipping file `{crate_name}`" ) ) ;
58+ continue ;
5959 }
6060
61- println ! (
62- "uploading completed; use `upload-index {}` for an incremental run" ,
63- repo. head_oid( ) ?
64- ) ;
65- Ok ( ( ) )
66- } )
67- . await
61+ let contents = tokio:: fs:: read_to_string ( & path) . await ?;
62+ storage. sync_index ( crate_name, Some ( contents) ) . await ?;
63+ }
64+
65+ println ! (
66+ "uploading completed; use `upload-index {}` for an incremental run" ,
67+ repo. head_oid( ) ?
68+ ) ;
69+ Ok ( ( ) )
6870}
0 commit comments