@@ -4,6 +4,8 @@ use std::path::{Path, PathBuf};
44use std:: process:: ExitStatus ;
55use std:: { env, fs, time} ;
66
7+ use eyre:: Context ;
8+
79use super :: engine:: Engine ;
810use super :: shared:: * ;
911use crate :: cargo:: CargoMetadata ;
@@ -114,7 +116,6 @@ fn create_volume_dir(
114116 . arg ( container)
115117 . args ( & [ "sh" , "-c" , & format ! ( "mkdir -p '{}'" , dir. as_posix( ) ?) ] )
116118 . run_and_get_status ( msg_info, false )
117- . map_err ( Into :: into)
118119}
119120
120121// copy files for a docker volume, for remote host support
@@ -130,7 +131,7 @@ fn copy_volume_files(
130131 . arg ( src. to_utf8 ( ) ?)
131132 . arg ( format ! ( "{container}:{}" , dst. as_posix( ) ?) )
132133 . run_and_get_status ( msg_info, false )
133- . map_err ( Into :: into)
134+ . map ( Into :: into)
134135}
135136
136137fn is_cachedir_tag ( path : & Path ) -> Result < bool > {
@@ -223,9 +224,15 @@ pub fn copy_volume_container_cargo(
223224 } else {
224225 // can copy a limit subset of files: the rest is present.
225226 create_volume_dir ( engine, container, & dst, msg_info) ?;
226- for entry in fs:: read_dir ( cargo_dir) ? {
227+ for entry in fs:: read_dir ( cargo_dir)
228+ . wrap_err_with ( || format ! ( "when reading directory {cargo_dir:?}" ) ) ?
229+ {
227230 let file = entry?;
228- let basename = file. file_name ( ) . to_utf8 ( ) ?. to_string ( ) ;
231+ let basename = file
232+ . file_name ( )
233+ . to_utf8 ( )
234+ . wrap_err_with ( || format ! ( "when reading file {file:?}" ) ) ?
235+ . to_string ( ) ;
229236 if !basename. starts_with ( '.' ) && !matches ! ( basename. as_ref( ) , "git" | "registry" ) {
230237 copy_volume_files ( engine, container, & file. path ( ) , & dst, msg_info) ?;
231238 }
@@ -248,7 +255,7 @@ where
248255{
249256 let mut had_symlinks = false ;
250257
251- for entry in fs:: read_dir ( src) ? {
258+ for entry in fs:: read_dir ( src) . wrap_err_with ( || format ! ( "when reading directory {src:?}" ) ) ? {
252259 let file = entry?;
253260 if skip ( & file, depth) {
254261 continue ;
@@ -257,7 +264,8 @@ where
257264 let src_path = file. path ( ) ;
258265 let dst_path = dst. join ( file. file_name ( ) ) ;
259266 if file. file_type ( ) ?. is_file ( ) {
260- fs:: copy ( & src_path, & dst_path) ?;
267+ fs:: copy ( & src_path, & dst_path)
268+ . wrap_err_with ( || format ! ( "when copying file {src_path:?} -> {dst_path:?}" ) ) ?;
261269 } else if file. file_type ( ) ?. is_dir ( ) {
262270 fs:: create_dir ( & dst_path) . ok ( ) ;
263271 had_symlinks = copy_dir ( & src_path, & dst_path, copy_symlinks, depth + 1 , skip) ?;
@@ -604,7 +612,6 @@ rm \"{PATH}\"
604612 . arg ( container)
605613 . args ( & [ "sh" , "-c" , & script. join ( "\n " ) ] )
606614 . run_and_get_status ( msg_info, true )
607- . map_err ( Into :: into)
608615}
609616
610617fn copy_volume_container_project (
@@ -657,7 +664,6 @@ fn run_and_get_status(engine: &Engine, args: &[&str], msg_info: MessageInfo) ->
657664 command ( engine)
658665 . args ( args)
659666 . run_and_get_status ( msg_info, true )
660- . map_err ( Into :: into)
661667}
662668
663669pub fn volume_create ( engine : & Engine , volume : & str , msg_info : MessageInfo ) -> Result < ExitStatus > {
@@ -673,7 +679,6 @@ pub fn volume_exists(engine: &Engine, volume: &str, msg_info: MessageInfo) -> Re
673679 . args ( & [ "volume" , "inspect" , volume] )
674680 . run_and_get_output ( msg_info)
675681 . map ( |output| output. status . success ( ) )
676- . map_err ( Into :: into)
677682}
678683
679684pub fn container_stop (
@@ -805,7 +810,7 @@ pub(crate) fn run(
805810
806811 // 2. create our volume to copy all our data over to
807812 if let VolumeId :: Discard ( ref id) = volume {
808- volume_create ( engine, id, msg_info) ?;
813+ volume_create ( engine, id, msg_info) . wrap_err ( "when creating volume" ) ?;
809814 }
810815 let _volume_deletter = DeleteVolume ( engine, & volume, msg_info) ;
811816
@@ -825,9 +830,11 @@ pub(crate) fn run(
825830 cwd,
826831 |_, val| mount_path ( val) ,
827832 |( src, dst) | volumes. push ( ( src, dst) ) ,
828- ) ?;
833+ )
834+ . wrap_err ( "could not determine mount points" ) ?;
829835
830- docker_seccomp ( & mut docker, engine. kind , target, metadata) ?;
836+ docker_seccomp ( & mut docker, engine. kind , target, metadata)
837+ . wrap_err ( "when copying seccomp profile" ) ?;
831838
832839 // Prevent `bin` from being mounted inside the Docker container.
833840 docker. args ( & [ "-v" , & format ! ( "{mount_prefix}/cargo/bin" ) ] ) ;
@@ -871,15 +878,17 @@ pub(crate) fn run(
871878 target,
872879 mount_prefix_path,
873880 msg_info,
874- ) ?;
881+ )
882+ . wrap_err ( "when copying xargo" ) ?;
875883 copy_volume_container_cargo (
876884 engine,
877885 & container,
878886 & dirs. cargo ,
879887 mount_prefix_path,
880888 false ,
881889 msg_info,
882- ) ?;
890+ )
891+ . wrap_err ( "when copying cargo" ) ?;
883892 copy_volume_container_rust (
884893 engine,
885894 & container,
@@ -888,7 +897,8 @@ pub(crate) fn run(
888897 mount_prefix_path,
889898 false ,
890899 msg_info,
891- ) ?;
900+ )
901+ . wrap_err ( "when copying rust" ) ?;
892902 } else {
893903 // need to copy over the target triple if it hasn't been previously copied
894904 copy_volume_container_rust_triple (
@@ -899,14 +909,16 @@ pub(crate) fn run(
899909 mount_prefix_path,
900910 true ,
901911 msg_info,
902- ) ?;
912+ )
913+ . wrap_err ( "when copying rust target files" ) ?;
903914 }
904915 let mount_root = if mount_volumes {
905916 // cannot panic: absolute unix path, must have root
906917 let rel_mount_root = dirs. mount_root . strip_prefix ( '/' ) . unwrap ( ) ;
907918 let mount_root = mount_prefix_path. join ( rel_mount_root) ;
908919 if !rel_mount_root. is_empty ( ) {
909- create_volume_dir ( engine, & container, mount_root. parent ( ) . unwrap ( ) , msg_info) ?;
920+ create_volume_dir ( engine, & container, mount_root. parent ( ) . unwrap ( ) , msg_info)
921+ . wrap_err ( "when creating mount root" ) ?;
910922 }
911923 mount_root
912924 } else {
@@ -920,7 +932,8 @@ pub(crate) fn run(
920932 & volume,
921933 copy_cache,
922934 msg_info,
923- ) ?;
935+ )
936+ . wrap_err ( "when copying project" ) ?;
924937
925938 let mut copied = vec ! [
926939 ( & dirs. xargo, mount_prefix_path. join( "xargo" ) ) ,
0 commit comments