@@ -20,7 +20,7 @@ const WASM_CONTENT_TYPE: &str = "application/wasm";
2020/// Construct a LockedApp from the given Application. Any buffered component
2121/// sources will be written to the given `working_dir`.
2222pub fn build_locked_app ( app : Application , working_dir : impl Into < PathBuf > ) -> Result < LockedApp > {
23- let working_dir = working_dir. into ( ) ;
23+ let working_dir = working_dir. into ( ) . canonicalize ( ) ? ;
2424 LockedAppBuilder { working_dir } . build ( app)
2525}
2626
@@ -51,7 +51,7 @@ impl LockedAppBuilder {
5151 builder. string (
5252 "origin" ,
5353 match info. origin {
54- spin_manifest:: ApplicationOrigin :: File ( path) => file_uri ( & path, false ) ?,
54+ spin_manifest:: ApplicationOrigin :: File ( path) => file_uri ( & path) ?,
5555 spin_manifest:: ApplicationOrigin :: Bindle { id, server } => {
5656 format ! ( "bindle+{server}?id={id}" )
5757 }
@@ -145,7 +145,7 @@ impl LockedAppBuilder {
145145 } ;
146146 LockedComponentSource {
147147 content_type : WASM_CONTENT_TYPE . into ( ) ,
148- content : content_ref_path ( & path, false ) ?,
148+ content : content_ref_path ( & path) ?,
149149 }
150150 } ;
151151
@@ -157,7 +157,7 @@ impl LockedAppBuilder {
157157 . into_iter ( )
158158 . map ( |mount| {
159159 Ok ( ContentPath {
160- content : content_ref_path ( & mount. host , true ) ?,
160+ content : content_ref_path ( & mount. host ) ?,
161161 path : mount. guest . into ( ) ,
162162 } )
163163 } )
@@ -176,20 +176,21 @@ impl LockedAppBuilder {
176176 }
177177}
178178
179- fn content_ref_path ( path : & Path , is_dir : bool ) -> Result < ContentRef > {
179+ fn content_ref_path ( path : & Path ) -> Result < ContentRef > {
180180 Ok ( ContentRef {
181- source : Some ( file_uri ( path, is_dir ) ?) ,
181+ source : Some ( file_uri ( path) ?) ,
182182 ..Default :: default ( )
183183 } )
184184}
185185
186- fn file_uri ( path : & Path , is_dir : bool ) -> Result < String > {
187- let uri = if is_dir {
188- url:: Url :: from_directory_path ( path)
186+ fn file_uri ( path : & Path ) -> Result < String > {
187+ let path = path. canonicalize ( ) ?;
188+ let uri = if path. is_dir ( ) {
189+ url:: Url :: from_directory_path ( & path)
189190 } else {
190- url:: Url :: from_file_path ( path)
191+ url:: Url :: from_file_path ( & path)
191192 }
192- . map_err ( |err | anyhow ! ( "Could not construct file URI: {err :?}" ) ) ?;
193+ . map_err ( |_ | anyhow ! ( "Could not construct file URI for {path :?}" ) ) ?;
193194 Ok ( uri. to_string ( ) )
194195}
195196
@@ -211,7 +212,7 @@ mod tests {
211212 [[component]]
212213 id = "test-component"
213214 source = "test-source.wasm"
214- files = ["content/* "]
215+ files = ["static.txt "]
215216 allowed_http_hosts = ["example.com"]
216217 [component.config]
217218 test_config = "{{test_var}}"
@@ -220,7 +221,7 @@ mod tests {
220221
221222 [[component]]
222223 id = "test-component-2"
223- source = "test-source-2 .wasm"
224+ source = "test-source.wasm"
224225 allowed_http_hosts = ["insecure:allow-all"]
225226 [component.trigger]
226227 route = "/other"
@@ -230,6 +231,8 @@ mod tests {
230231 let tempdir = TempDir :: new ( ) . expect ( "tempdir" ) ;
231232 std:: env:: set_current_dir ( tempdir. path ( ) ) . unwrap ( ) ;
232233 std:: fs:: write ( "spin.toml" , TEST_MANIFEST ) . expect ( "write manifest" ) ;
234+ std:: fs:: write ( "test-source.wasm" , "not actual wasm" ) . expect ( "write source" ) ;
235+ std:: fs:: write ( "static.txt" , "content" ) . expect ( "write static" ) ;
233236 let app = spin_loader:: local:: from_file ( "spin.toml" , & tempdir, & None )
234237 . await
235238 . expect ( "load app" ) ;
0 commit comments