@@ -48,7 +48,8 @@ fn copy_dir(src: &Path, dest: &Path) -> Result<(), Error> {
48
48
let dest = crate :: utils:: normalize_path ( dest) ;
49
49
50
50
let src_components = src. components ( ) . count ( ) ;
51
- for entry in WalkDir :: new ( & src) {
51
+ let mut entries = WalkDir :: new ( & src) . into_iter ( ) ;
52
+ while let Some ( entry) = entries. next ( ) {
52
53
let entry = entry?;
53
54
54
55
let mut components = entry. path ( ) . components ( ) ;
@@ -58,7 +59,13 @@ fn copy_dir(src: &Path, dest: &Path) -> Result<(), Error> {
58
59
let path = components. as_path ( ) ;
59
60
60
61
if entry. file_type ( ) . is_dir ( ) {
61
- std:: fs:: create_dir_all ( dest. join ( path) ) ?;
62
+ // don't copy /target directory
63
+ if entry. file_name ( ) == "target" && entry. depth ( ) == 1 {
64
+ info ! ( "ignoring top-level target directory {}" , path. display( ) ) ;
65
+ entries. skip_current_dir ( ) ;
66
+ } else {
67
+ std:: fs:: create_dir_all ( dest. join ( path) ) ?;
68
+ }
62
69
} else {
63
70
std:: fs:: copy ( src. join ( path) , dest. join ( path) ) ?;
64
71
}
@@ -90,4 +97,22 @@ mod tests {
90
97
91
98
Ok ( ( ) )
92
99
}
100
+
101
+ #[ test]
102
+ fn test_no_copy_target ( ) -> Result < ( ) , Error > {
103
+ let ( src, dest) = ( tempfile:: tempdir ( ) ?, tempfile:: tempdir ( ) ?) ;
104
+ std:: fs:: create_dir ( src. path ( ) . join ( "target" ) ) ?;
105
+ std:: fs:: write (
106
+ src. path ( ) . join ( "target" ) . join ( "a.out" ) ,
107
+ b"this is not actually an ELF file" ,
108
+ ) ?;
109
+ println ! ( "made subdirs and files" ) ;
110
+
111
+ super :: copy_dir ( src. path ( ) , dest. path ( ) ) ?;
112
+ println ! ( "copied" ) ;
113
+
114
+ assert ! ( !dest. path( ) . join( "target" ) . exists( ) ) ;
115
+
116
+ Ok ( ( ) )
117
+ }
93
118
}
0 commit comments