@@ -11,7 +11,7 @@ use iroh_bytes::{
1111 self , handle_connection, DownloadProgress , EventSender , RequestAuthorizationHandler ,
1212 } ,
1313 store:: { ExportMode , ImportMode , ImportProgress } ,
14- BlobFormat , Hash , HashAndFormat , TempTag ,
14+ BlobFormat , Hash , HashAndFormat , TempTag , get :: fsm :: DecodeError ,
1515} ;
1616use iroh_bytes_util:: get_hash_seq_and_sizes;
1717use iroh_net:: { key:: SecretKey , MagicEndpoint } ;
@@ -342,8 +342,7 @@ fn get_export_path(root: &Path, name: &str) -> anyhow::Result<PathBuf> {
342342 Ok ( path)
343343}
344344
345- async fn export ( db : impl iroh_bytes:: store:: Store , root : HashAndFormat ) -> anyhow:: Result < ( ) > {
346- let collection = crate :: collection:: Collection :: load ( & db, & root. hash ) . await ?;
345+ async fn export ( db : impl iroh_bytes:: store:: Store , collection : Collection ) -> anyhow:: Result < ( ) > {
347346 let root = std:: env:: current_dir ( ) ?;
348347 for ( name, hash) in collection. iter ( ) {
349348 let target = get_export_path ( & root, name) ?;
@@ -584,6 +583,30 @@ pub async fn show_download_progress(
584583 Ok ( ( ) )
585584}
586585
586+ fn show_get_error ( e : anyhow:: Error ) -> anyhow:: Error {
587+ if let Some ( err) = e. downcast_ref :: < DecodeError > ( ) {
588+ let error_text = match err {
589+ DecodeError :: NotFound => {
590+ "provide side no longer has a file" . to_string ( )
591+ }
592+ DecodeError :: LeafNotFound ( _) | DecodeError :: ParentNotFound ( _) => {
593+ "provide side no longer has part of a file" . to_string ( )
594+ }
595+ DecodeError :: LeafHashMismatch ( _) | DecodeError :: ParentHashMismatch ( _) => {
596+ "provide side sent wrong data" . to_string ( )
597+ }
598+ DecodeError :: Io ( err) => {
599+ format ! ( "generic network error: {}" , err)
600+ }
601+ DecodeError :: Read ( err) => {
602+ format ! ( "error reading data from quinn: {}" , err)
603+ }
604+ } ;
605+ eprintln ! ( "error: {}" , error_text) ;
606+ }
607+ e
608+ }
609+
587610async fn get ( args : GetArgs ) -> anyhow:: Result < ( ) > {
588611 let ticket = args. ticket ;
589612 let addr = ticket. node_addr ( ) . clone ( ) ;
@@ -617,26 +640,36 @@ async fn get(args: GetArgs) -> anyhow::Result<()> {
617640 let ( send, recv) = flume:: bounded ( 32 ) ;
618641 let progress = iroh_bytes:: util:: progress:: FlumeProgressSender :: new ( send) ;
619642 let ( _hash_seq, sizes) =
620- get_hash_seq_and_sizes ( & connection, & hash_and_format. hash , 1024 * 1024 * 32 ) . await ?;
643+ get_hash_seq_and_sizes ( & connection, & hash_and_format. hash , 1024 * 1024 * 32 ) . await
644+ . map_err ( show_get_error) ?;
621645 let total_size = sizes. iter ( ) . sum :: < u64 > ( ) ;
622646 let total_files = sizes. len ( ) . saturating_sub ( 1 ) ;
623647 let payload_size = sizes. iter ( ) . skip ( 1 ) . sum :: < u64 > ( ) ;
624- eprintln ! ( "getting {} blobs, {}" , sizes. len( ) , HumanBytes ( total_size) ) ;
625648 eprintln ! (
626649 "getting collection {} {} files, {}" ,
627650 print_hash( ticket. hash( ) , args. common. format) ,
628651 total_files,
629652 HumanBytes ( payload_size)
630653 ) ;
654+ // print the details of the collection only in verbose mode
655+ if args. common . verbose > 0 {
656+ eprintln ! ( "getting {} blobs in total, {}" , sizes. len( ) , HumanBytes ( total_size) ) ;
657+ }
631658 let _task = tokio:: spawn ( show_download_progress ( recv. into_stream ( ) , total_size) ) ;
632- let _stats = get:: get ( & db, connection, & hash_and_format, progress) . await ?;
659+ let _stats = get:: get ( & db, connection, & hash_and_format, progress) . await
660+ . map_err ( show_get_error) ?;
661+ let collection = Collection :: load ( & db, & hash_and_format. hash ) . await ?;
633662 if args. common . verbose > 0 {
634- let collection = Collection :: load ( & db, & hash_and_format. hash ) . await ?;
635663 for ( name, hash) in collection. iter ( ) {
636664 println ! ( " {} {name}" , print_hash( hash, args. common. format) ) ;
637665 }
638666 }
639- export ( db, hash_and_format) . await ?;
667+ if let Some ( ( name, _) ) = collection. iter ( ) . next ( ) {
668+ if let Some ( first) = name. split ( '/' ) . next ( ) {
669+ println ! ( "downloading to {}" , first) ;
670+ }
671+ }
672+ export ( db, collection) . await ?;
640673 std:: fs:: remove_dir_all ( iroh_data_dir) ?;
641674 Ok ( ( ) )
642675}
@@ -651,9 +684,6 @@ async fn main() -> anyhow::Result<()> {
651684 } ;
652685 match res {
653686 Ok ( ( ) ) => std:: process:: exit ( 0 ) ,
654- Err ( e) => {
655- eprintln ! ( "error: {}" , e) ;
656- std:: process:: exit ( 1 )
657- }
687+ Err ( _) => std:: process:: exit ( 1 ) ,
658688 }
659689}
0 commit comments