1
1
#![ deny( missing_docs) ]
2
2
3
- use crate :: assets:: {
4
- change_file_permission, create_dir, ensure_all_under, ensure_under, to_relative,
5
- } ;
3
+ use crate :: assets:: { create_dir, ensure_all_under, ensure_under, to_relative} ;
6
4
use anyhow:: { anyhow, bail, ensure, Context , Result } ;
7
5
use futures:: { future, stream, StreamExt } ;
8
6
use spin_manifest:: DirectoryMount ;
9
7
use std:: {
10
8
path:: { Path , PathBuf } ,
11
9
vec,
12
10
} ;
13
- use tracing:: log;
14
11
use walkdir:: WalkDir ;
15
12
16
13
use super :: config:: { RawDirectoryPlacement , RawFileMount } ;
@@ -22,10 +19,9 @@ pub(crate) async fn prepare_component(
22
19
src : impl AsRef < Path > ,
23
20
base_dst : impl AsRef < Path > ,
24
21
id : & str ,
25
- allow_transient_write : bool ,
26
22
exclude_files : & [ String ] ,
27
23
) -> Result < Vec < DirectoryMount > > {
28
- log :: info!(
24
+ tracing :: info!(
29
25
"Mounting files from '{}' to '{}'" ,
30
26
src. as_ref( ) . display( ) ,
31
27
base_dst. as_ref( ) . display( )
@@ -34,7 +30,7 @@ pub(crate) async fn prepare_component(
34
30
let files = collect ( raw_mounts, exclude_files, src) ?;
35
31
let host = create_dir ( & base_dst, id) . await ?;
36
32
let guest = "/" . to_string ( ) ;
37
- copy_all ( & files, & host, allow_transient_write ) . await ?;
33
+ copy_all ( & files, & host) . await ?;
38
34
39
35
Ok ( vec ! [ DirectoryMount { guest, host } ] )
40
36
}
@@ -173,7 +169,7 @@ fn collect_placement(
173
169
/// Generate a vector of file mounts given a file pattern.
174
170
fn collect_pattern ( pattern : & str , rel : impl AsRef < Path > ) -> Result < Vec < FileMount > > {
175
171
let abs = rel. as_ref ( ) . join ( pattern) ;
176
- log :: trace!( "Resolving asset file pattern '{:?}'" , abs) ;
172
+ tracing :: trace!( "Resolving asset file pattern '{:?}'" , abs) ;
177
173
178
174
let matches = glob:: glob ( & abs. to_string_lossy ( ) ) ?;
179
175
let specifiers = matches
@@ -186,53 +182,36 @@ fn collect_pattern(pattern: &str, rel: impl AsRef<Path>) -> Result<Vec<FileMount
186
182
}
187
183
188
184
/// Copy all files to the mount directory.
189
- async fn copy_all (
190
- files : & [ FileMount ] ,
191
- dir : impl AsRef < Path > ,
192
- allow_transient_write : bool ,
193
- ) -> Result < ( ) > {
194
- let copy_futures = files. iter ( ) . map ( |f| copy ( f, & dir, allow_transient_write) ) ;
185
+ async fn copy_all ( files : & [ FileMount ] , dir : impl AsRef < Path > ) -> Result < ( ) > {
186
+ let copy_futures = files. iter ( ) . map ( |f| copy ( f, & dir) ) ;
195
187
let errors = stream:: iter ( copy_futures)
196
188
. buffer_unordered ( crate :: MAX_PARALLEL_ASSET_PROCESSING )
197
189
. filter_map ( |r| future:: ready ( r. err ( ) ) )
198
- . map ( |e| log :: error!( "{:?}" , e ) )
190
+ . map ( |e| tracing :: error!( "{e :?}" ) )
199
191
. count ( )
200
192
. await ;
201
193
ensure ! (
202
194
errors == 0 ,
203
- "Error copying assets: {} file(s) not copied" ,
204
- errors
195
+ "Error copying assets: {errors} file(s) not copied" ,
205
196
) ;
206
197
Ok ( ( ) )
207
198
}
208
199
209
200
/// Copy a single file to the mount directory, setting it as read-only.
210
- async fn copy ( file : & FileMount , dir : impl AsRef < Path > , allow_transient_write : bool ) -> Result < ( ) > {
201
+ async fn copy ( file : & FileMount , dir : impl AsRef < Path > ) -> Result < ( ) > {
211
202
let from = & file. src ;
212
203
let to = dir. as_ref ( ) . join ( & file. relative_dst ) ;
213
204
214
205
ensure_under ( & dir. as_ref ( ) , & to. as_path ( ) ) ?;
215
206
216
- log:: trace!(
217
- "Copying asset file '{}' -> '{}'" ,
218
- from. display( ) ,
219
- to. display( )
220
- ) ;
207
+ tracing:: trace!( "Copying asset file '{from:?}' -> '{to:?}'" ) ;
221
208
222
- tokio:: fs:: create_dir_all ( to. parent ( ) . expect ( "Cannot copy to file '/'" ) ) . await ?;
223
-
224
- // if destination file is read-only, set it to writable first
225
- let metadata = tokio:: fs:: metadata ( & to) . await ;
226
- if metadata. is_ok ( ) && metadata. unwrap ( ) . permissions ( ) . readonly ( ) {
227
- change_file_permission ( & to, true ) . await ?;
228
- }
209
+ tokio:: fs:: create_dir_all ( to. parent ( ) . context ( "Cannot copy to file '/'" ) ?) . await ?;
229
210
230
211
let _ = tokio:: fs:: copy ( & from, & to)
231
212
. await
232
213
. with_context ( || anyhow ! ( "Error copying asset file '{}'" , from. display( ) ) ) ?;
233
214
234
- change_file_permission ( & to, allow_transient_write) . await ?;
235
-
236
215
Ok ( ( ) )
237
216
}
238
217
0 commit comments