@@ -20,7 +20,7 @@ const WASM_CONTENT_TYPE: &str = "application/wasm";
20
20
/// Construct a LockedApp from the given Application. Any buffered component
21
21
/// sources will be written to the given `working_dir`.
22
22
pub 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 ( ) ? ;
24
24
LockedAppBuilder { working_dir } . build ( app)
25
25
}
26
26
@@ -51,7 +51,7 @@ impl LockedAppBuilder {
51
51
builder. string (
52
52
"origin" ,
53
53
match info. origin {
54
- spin_manifest:: ApplicationOrigin :: File ( path) => file_uri ( & path, false ) ?,
54
+ spin_manifest:: ApplicationOrigin :: File ( path) => file_uri ( & path) ?,
55
55
spin_manifest:: ApplicationOrigin :: Bindle { id, server } => {
56
56
format ! ( "bindle+{server}?id={id}" )
57
57
}
@@ -145,7 +145,7 @@ impl LockedAppBuilder {
145
145
} ;
146
146
LockedComponentSource {
147
147
content_type : WASM_CONTENT_TYPE . into ( ) ,
148
- content : content_ref_path ( & path, false ) ?,
148
+ content : content_ref_path ( & path) ?,
149
149
}
150
150
} ;
151
151
@@ -157,7 +157,7 @@ impl LockedAppBuilder {
157
157
. into_iter ( )
158
158
. map ( |mount| {
159
159
Ok ( ContentPath {
160
- content : content_ref_path ( & mount. host , true ) ?,
160
+ content : content_ref_path ( & mount. host ) ?,
161
161
path : mount. guest . into ( ) ,
162
162
} )
163
163
} )
@@ -176,20 +176,21 @@ impl LockedAppBuilder {
176
176
}
177
177
}
178
178
179
- fn content_ref_path ( path : & Path , is_dir : bool ) -> Result < ContentRef > {
179
+ fn content_ref_path ( path : & Path ) -> Result < ContentRef > {
180
180
Ok ( ContentRef {
181
- source : Some ( file_uri ( path, is_dir ) ?) ,
181
+ source : Some ( file_uri ( path) ?) ,
182
182
..Default :: default ( )
183
183
} )
184
184
}
185
185
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)
189
190
} else {
190
- url:: Url :: from_file_path ( path)
191
+ url:: Url :: from_file_path ( & path)
191
192
}
192
- . map_err ( |err | anyhow ! ( "Could not construct file URI: {err :?}" ) ) ?;
193
+ . map_err ( |_ | anyhow ! ( "Could not construct file URI for {path :?}" ) ) ?;
193
194
Ok ( uri. to_string ( ) )
194
195
}
195
196
@@ -211,7 +212,7 @@ mod tests {
211
212
[[component]]
212
213
id = "test-component"
213
214
source = "test-source.wasm"
214
- files = ["content/* "]
215
+ files = ["static.txt "]
215
216
allowed_http_hosts = ["example.com"]
216
217
[component.config]
217
218
test_config = "{{test_var}}"
@@ -220,7 +221,7 @@ mod tests {
220
221
221
222
[[component]]
222
223
id = "test-component-2"
223
- source = "test-source-2 .wasm"
224
+ source = "test-source.wasm"
224
225
allowed_http_hosts = ["insecure:allow-all"]
225
226
[component.trigger]
226
227
route = "/other"
@@ -230,6 +231,8 @@ mod tests {
230
231
let tempdir = TempDir :: new ( ) . expect ( "tempdir" ) ;
231
232
std:: env:: set_current_dir ( tempdir. path ( ) ) . unwrap ( ) ;
232
233
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" ) ;
233
236
let app = spin_loader:: local:: from_file ( "spin.toml" , & tempdir, & None )
234
237
. await
235
238
. expect ( "load app" ) ;
0 commit comments