11#![ allow( dead_code) ] // Refactor WIP
22
3- use std:: path:: { Path , PathBuf } ;
3+ use std:: path:: PathBuf ;
44
55use anyhow:: { ensure, Context , Result } ;
66use async_trait:: async_trait;
@@ -10,6 +10,8 @@ use spin_app::{
1010} ;
1111use spin_core:: StoreBuilder ;
1212
13+ use crate :: parse_file_url;
14+
1315pub struct TriggerLoader {
1416 working_dir : PathBuf ,
1517 allow_transient_write : bool ,
@@ -26,10 +28,10 @@ impl TriggerLoader {
2628
2729#[ async_trait]
2830impl Loader for TriggerLoader {
29- async fn load_app ( & self , uri : & str ) -> Result < LockedApp > {
30- let path = unwrap_file_uri ( uri ) ?;
31+ async fn load_app ( & self , url : & str ) -> Result < LockedApp > {
32+ let path = parse_file_url ( url ) ?;
3133 let contents =
32- std:: fs:: read ( path) . with_context ( || format ! ( "failed to read manifest at {path:?}" ) ) ?;
34+ std:: fs:: read ( & path) . with_context ( || format ! ( "failed to read manifest at {path:?}" ) ) ?;
3335 let app =
3436 serde_json:: from_slice ( & contents) . context ( "failed to parse app lock file JSON" ) ?;
3537 Ok ( app)
@@ -45,8 +47,8 @@ impl Loader for TriggerLoader {
4547 . source
4648 . as_ref ( )
4749 . context ( "LockedComponentSource missing source field" ) ?;
48- let path = unwrap_file_uri ( source) ?;
49- spin_core:: Module :: from_file ( engine, path)
50+ let path = parse_file_url ( source) ?;
51+ spin_core:: Module :: from_file ( engine, & path)
5052 . with_context ( || format ! ( "loading module {path:?}" ) )
5153 }
5254
@@ -61,7 +63,7 @@ impl Loader for TriggerLoader {
6163 . source
6264 . as_deref ( )
6365 . with_context ( || format ! ( "Missing 'source' on files mount {content_dir:?}" ) ) ?;
64- let source_path = self . working_dir . join ( unwrap_file_uri ( source_uri) ?) ;
66+ let source_path = self . working_dir . join ( parse_file_url ( source_uri) ?) ;
6567 ensure ! (
6668 source_path. is_dir( ) ,
6769 "TriggerLoader only supports directory mounts; {source_path:?} is not a directory"
@@ -76,10 +78,3 @@ impl Loader for TriggerLoader {
7678 Ok ( ( ) )
7779 }
7880}
79-
80- fn unwrap_file_uri ( uri : & str ) -> Result < & Path > {
81- Ok ( Path :: new (
82- uri. strip_prefix ( "file://" )
83- . context ( "TriggerLoader supports only file:// URIs" ) ?,
84- ) )
85- }
0 commit comments