33use std:: path:: Path ;
44use std:: path:: PathBuf ;
55
6- use anyhow:: bail;
7- use anyhow:: Context ;
8- use anyhow:: Result ;
96use futures:: future:: BoxFuture ;
107use futures:: future:: LocalBoxFuture ;
118use futures:: FutureExt ;
9+ use miette:: bail;
10+ use miette:: Context ;
11+ use miette:: IntoDiagnostic ;
12+ use miette:: Result ;
1213
1314use crate :: shell:: types:: ExecuteResult ;
1415use crate :: shell:: types:: ShellPipeWriter ;
@@ -87,7 +88,9 @@ async fn do_copy_operation(
8788 bail ! ( "source was a directory; maybe specify -r" )
8889 }
8990 } else {
90- tokio:: fs:: copy ( & from. path , & to. path ) . await ?;
91+ tokio:: fs:: copy ( & from. path , & to. path )
92+ . await
93+ . into_diagnostic ( ) ?;
9194 }
9295 Ok ( ( ) )
9396}
@@ -100,13 +103,15 @@ fn copy_dir_recursively(
100103 async move {
101104 tokio:: fs:: create_dir_all ( & to)
102105 . await
103- . with_context ( || format ! ( "Creating {}" , to. display( ) ) ) ?;
106+ . into_diagnostic ( )
107+ . context ( miette:: miette!( "Creating {}" , to. display( ) ) ) ?;
104108 let mut read_dir = tokio:: fs:: read_dir ( & from)
105109 . await
106- . with_context ( || format ! ( "Reading {}" , from. display( ) ) ) ?;
110+ . into_diagnostic ( )
111+ . context ( miette:: miette!( "Reading {}" , from. display( ) ) ) ?;
107112
108- while let Some ( entry) = read_dir. next_entry ( ) . await ? {
109- let file_type = entry. file_type ( ) . await ?;
113+ while let Some ( entry) = read_dir. next_entry ( ) . await . into_diagnostic ( ) ? {
114+ let file_type = entry. file_type ( ) . await . into_diagnostic ( ) ?;
110115 let new_from = from. join ( entry. file_name ( ) ) ;
111116 let new_to = to. join ( entry. file_name ( ) ) ;
112117
@@ -117,9 +122,12 @@ fn copy_dir_recursively(
117122 format ! ( "Dir {} to {}" , new_from. display( ) , new_to. display( ) )
118123 } ) ?;
119124 } else if file_type. is_file ( ) {
120- tokio:: fs:: copy ( & new_from, & new_to) . await . with_context ( || {
121- format ! ( "Copying {} to {}" , new_from. display( ) , new_to. display( ) )
122- } ) ?;
125+ tokio:: fs:: copy ( & new_from, & new_to)
126+ . await
127+ . into_diagnostic ( )
128+ . with_context ( || {
129+ format ! ( "Copying {} to {}" , new_from. display( ) , new_to. display( ) )
130+ } ) ?;
123131 }
124132 }
125133
0 commit comments