@@ -4,6 +4,8 @@ use std::path::{Path, PathBuf};
4
4
use std:: process:: ExitStatus ;
5
5
use std:: { env, fs, time} ;
6
6
7
+ use eyre:: Context ;
8
+
7
9
use super :: engine:: Engine ;
8
10
use super :: shared:: * ;
9
11
use crate :: cargo:: CargoMetadata ;
@@ -114,7 +116,6 @@ fn create_volume_dir(
114
116
. arg ( container)
115
117
. args ( & [ "sh" , "-c" , & format ! ( "mkdir -p '{}'" , dir. as_posix( ) ?) ] )
116
118
. run_and_get_status ( msg_info, false )
117
- . map_err ( Into :: into)
118
119
}
119
120
120
121
// copy files for a docker volume, for remote host support
@@ -130,7 +131,6 @@ fn copy_volume_files(
130
131
. arg ( src. to_utf8 ( ) ?)
131
132
. arg ( format ! ( "{container}:{}" , dst. as_posix( ) ?) )
132
133
. run_and_get_status ( msg_info, false )
133
- . map_err ( Into :: into)
134
134
}
135
135
136
136
fn is_cachedir_tag ( path : & Path ) -> Result < bool > {
@@ -223,9 +223,15 @@ pub fn copy_volume_container_cargo(
223
223
} else {
224
224
// can copy a limit subset of files: the rest is present.
225
225
create_volume_dir ( engine, container, & dst, msg_info) ?;
226
- for entry in fs:: read_dir ( cargo_dir) ? {
226
+ for entry in fs:: read_dir ( cargo_dir)
227
+ . wrap_err_with ( || format ! ( "when reading directory {cargo_dir:?}" ) ) ?
228
+ {
227
229
let file = entry?;
228
- let basename = file. file_name ( ) . to_utf8 ( ) ?. to_string ( ) ;
230
+ let basename = file
231
+ . file_name ( )
232
+ . to_utf8 ( )
233
+ . wrap_err_with ( || format ! ( "when reading file {file:?}" ) ) ?
234
+ . to_string ( ) ;
229
235
if !basename. starts_with ( '.' ) && !matches ! ( basename. as_ref( ) , "git" | "registry" ) {
230
236
copy_volume_files ( engine, container, & file. path ( ) , & dst, msg_info) ?;
231
237
}
@@ -248,7 +254,7 @@ where
248
254
{
249
255
let mut had_symlinks = false ;
250
256
251
- for entry in fs:: read_dir ( src) ? {
257
+ for entry in fs:: read_dir ( src) . wrap_err_with ( || format ! ( "when reading directory {src:?}" ) ) ? {
252
258
let file = entry?;
253
259
if skip ( & file, depth) {
254
260
continue ;
@@ -257,7 +263,8 @@ where
257
263
let src_path = file. path ( ) ;
258
264
let dst_path = dst. join ( file. file_name ( ) ) ;
259
265
if file. file_type ( ) ?. is_file ( ) {
260
- fs:: copy ( & src_path, & dst_path) ?;
266
+ fs:: copy ( & src_path, & dst_path)
267
+ . wrap_err_with ( || format ! ( "when copying file {src_path:?} -> {dst_path:?}" ) ) ?;
261
268
} else if file. file_type ( ) ?. is_dir ( ) {
262
269
fs:: create_dir ( & dst_path) . ok ( ) ;
263
270
had_symlinks = copy_dir ( & src_path, & dst_path, copy_symlinks, depth + 1 , skip) ?;
@@ -604,7 +611,6 @@ rm \"{PATH}\"
604
611
. arg ( container)
605
612
. args ( & [ "sh" , "-c" , & script. join ( "\n " ) ] )
606
613
. run_and_get_status ( msg_info, true )
607
- . map_err ( Into :: into)
608
614
}
609
615
610
616
fn copy_volume_container_project (
@@ -657,7 +663,6 @@ fn run_and_get_status(engine: &Engine, args: &[&str], msg_info: MessageInfo) ->
657
663
command ( engine)
658
664
. args ( args)
659
665
. run_and_get_status ( msg_info, true )
660
- . map_err ( Into :: into)
661
666
}
662
667
663
668
pub fn volume_create ( engine : & Engine , volume : & str , msg_info : MessageInfo ) -> Result < ExitStatus > {
@@ -673,7 +678,6 @@ pub fn volume_exists(engine: &Engine, volume: &str, msg_info: MessageInfo) -> Re
673
678
. args ( & [ "volume" , "inspect" , volume] )
674
679
. run_and_get_output ( msg_info)
675
680
. map ( |output| output. status . success ( ) )
676
- . map_err ( Into :: into)
677
681
}
678
682
679
683
pub fn container_stop (
@@ -805,7 +809,7 @@ pub(crate) fn run(
805
809
806
810
// 2. create our volume to copy all our data over to
807
811
if let VolumeId :: Discard ( ref id) = volume {
808
- volume_create ( engine, id, msg_info) ?;
812
+ volume_create ( engine, id, msg_info) . wrap_err ( "when creating volume" ) ?;
809
813
}
810
814
let _volume_deletter = DeleteVolume ( engine, & volume, msg_info) ;
811
815
@@ -825,9 +829,11 @@ pub(crate) fn run(
825
829
cwd,
826
830
|_, val| mount_path ( val) ,
827
831
|( src, dst) | volumes. push ( ( src, dst) ) ,
828
- ) ?;
832
+ )
833
+ . wrap_err ( "could not determine mount points" ) ?;
829
834
830
- docker_seccomp ( & mut docker, engine. kind , target, metadata) ?;
835
+ docker_seccomp ( & mut docker, engine. kind , target, metadata)
836
+ . wrap_err ( "when copying seccomp profile" ) ?;
831
837
832
838
// Prevent `bin` from being mounted inside the Docker container.
833
839
docker. args ( & [ "-v" , & format ! ( "{mount_prefix}/cargo/bin" ) ] ) ;
@@ -871,15 +877,17 @@ pub(crate) fn run(
871
877
target,
872
878
mount_prefix_path,
873
879
msg_info,
874
- ) ?;
880
+ )
881
+ . wrap_err ( "when copying xargo" ) ?;
875
882
copy_volume_container_cargo (
876
883
engine,
877
884
& container,
878
885
& dirs. cargo ,
879
886
mount_prefix_path,
880
887
false ,
881
888
msg_info,
882
- ) ?;
889
+ )
890
+ . wrap_err ( "when copying cargo" ) ?;
883
891
copy_volume_container_rust (
884
892
engine,
885
893
& container,
@@ -888,7 +896,8 @@ pub(crate) fn run(
888
896
mount_prefix_path,
889
897
false ,
890
898
msg_info,
891
- ) ?;
899
+ )
900
+ . wrap_err ( "when copying rust" ) ?;
892
901
} else {
893
902
// need to copy over the target triple if it hasn't been previously copied
894
903
copy_volume_container_rust_triple (
@@ -899,14 +908,16 @@ pub(crate) fn run(
899
908
mount_prefix_path,
900
909
true ,
901
910
msg_info,
902
- ) ?;
911
+ )
912
+ . wrap_err ( "when copying rust target files" ) ?;
903
913
}
904
914
let mount_root = if mount_volumes {
905
915
// cannot panic: absolute unix path, must have root
906
916
let rel_mount_root = dirs. mount_root . strip_prefix ( '/' ) . unwrap ( ) ;
907
917
let mount_root = mount_prefix_path. join ( rel_mount_root) ;
908
918
if !rel_mount_root. is_empty ( ) {
909
- create_volume_dir ( engine, & container, mount_root. parent ( ) . unwrap ( ) , msg_info) ?;
919
+ create_volume_dir ( engine, & container, mount_root. parent ( ) . unwrap ( ) , msg_info)
920
+ . wrap_err ( "when creating mount root" ) ?;
910
921
}
911
922
mount_root
912
923
} else {
@@ -920,7 +931,8 @@ pub(crate) fn run(
920
931
& volume,
921
932
copy_cache,
922
933
msg_info,
923
- ) ?;
934
+ )
935
+ . wrap_err ( "when copying project" ) ?;
924
936
925
937
let mut copied = vec ! [
926
938
( & dirs. xargo, mount_prefix_path. join( "xargo" ) ) ,
@@ -1029,7 +1041,7 @@ symlink_recurse \"${{prefix}}\"
1029
1041
. arg ( & container)
1030
1042
. args ( & [ "sh" , "-c" , & symlink. join ( "\n " ) ] )
1031
1043
. run_and_get_status ( msg_info, false )
1032
- . map_err :: < eyre :: ErrReport , _ > ( Into :: into ) ?;
1044
+ . wrap_err ( "when creating symlinks to provide consistent host/mount paths" ) ?;
1033
1045
1034
1046
// 6. execute our cargo command inside the container
1035
1047
let mut docker = subcommand ( engine, "exec" ) ;
0 commit comments