11#![ deny( missing_docs) ]
22
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} ;
64use anyhow:: { anyhow, bail, ensure, Context , Result } ;
75use futures:: { future, stream, StreamExt } ;
86use spin_manifest:: DirectoryMount ;
97use std:: {
108 path:: { Path , PathBuf } ,
119 vec,
1210} ;
13- use tracing:: log;
1411use walkdir:: WalkDir ;
1512
1613use super :: config:: { RawDirectoryPlacement , RawFileMount } ;
@@ -22,10 +19,9 @@ pub(crate) async fn prepare_component(
2219 src : impl AsRef < Path > ,
2320 base_dst : impl AsRef < Path > ,
2421 id : & str ,
25- allow_transient_write : bool ,
2622 exclude_files : & [ String ] ,
2723) -> Result < Vec < DirectoryMount > > {
28- log :: info!(
24+ tracing :: info!(
2925 "Mounting files from '{}' to '{}'" ,
3026 src. as_ref( ) . display( ) ,
3127 base_dst. as_ref( ) . display( )
@@ -34,7 +30,7 @@ pub(crate) async fn prepare_component(
3430 let files = collect ( raw_mounts, exclude_files, src) ?;
3531 let host = create_dir ( & base_dst, id) . await ?;
3632 let guest = "/" . to_string ( ) ;
37- copy_all ( & files, & host, allow_transient_write ) . await ?;
33+ copy_all ( & files, & host) . await ?;
3834
3935 Ok ( vec ! [ DirectoryMount { guest, host } ] )
4036}
@@ -173,7 +169,7 @@ fn collect_placement(
173169/// Generate a vector of file mounts given a file pattern.
174170fn collect_pattern ( pattern : & str , rel : impl AsRef < Path > ) -> Result < Vec < FileMount > > {
175171 let abs = rel. as_ref ( ) . join ( pattern) ;
176- log :: trace!( "Resolving asset file pattern '{:?}'" , abs) ;
172+ tracing :: trace!( "Resolving asset file pattern '{:?}'" , abs) ;
177173
178174 let matches = glob:: glob ( & abs. to_string_lossy ( ) ) ?;
179175 let specifiers = matches
@@ -186,53 +182,36 @@ fn collect_pattern(pattern: &str, rel: impl AsRef<Path>) -> Result<Vec<FileMount
186182}
187183
188184/// 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) ) ;
195187 let errors = stream:: iter ( copy_futures)
196188 . buffer_unordered ( crate :: MAX_PARALLEL_ASSET_PROCESSING )
197189 . filter_map ( |r| future:: ready ( r. err ( ) ) )
198- . map ( |e| log :: error!( "{:?}" , e ) )
190+ . map ( |e| tracing :: error!( "{e :?}" ) )
199191 . count ( )
200192 . await ;
201193 ensure ! (
202194 errors == 0 ,
203- "Error copying assets: {} file(s) not copied" ,
204- errors
195+ "Error copying assets: {errors} file(s) not copied" ,
205196 ) ;
206197 Ok ( ( ) )
207198}
208199
209200/// 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 < ( ) > {
211202 let from = & file. src ;
212203 let to = dir. as_ref ( ) . join ( & file. relative_dst ) ;
213204
214205 ensure_under ( & dir. as_ref ( ) , & to. as_path ( ) ) ?;
215206
216- log:: trace!(
217- "Copying asset file '{}' -> '{}'" ,
218- from. display( ) ,
219- to. display( )
220- ) ;
207+ tracing:: trace!( "Copying asset file '{from:?}' -> '{to:?}'" ) ;
221208
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 ?;
229210
230211 let _ = tokio:: fs:: copy ( & from, & to)
231212 . await
232213 . with_context ( || anyhow ! ( "Error copying asset file '{}'" , from. display( ) ) ) ?;
233214
234- change_file_permission ( & to, allow_transient_write) . await ?;
235-
236215 Ok ( ( ) )
237216}
238217
0 commit comments