@@ -16,12 +16,10 @@ use std::{fs, path::Path};
1616use tokio:: io:: AsyncReadExt ;
1717use tokio:: { io:: BufReader , net:: UnixListener } ;
1818
19- pub const SOCKET_NAME : & str = "metrics.sock" ;
20- const DEFAULT_MACOS_SOCKET : & str = "/tmp/com.prime.worker/" ;
21- const DEFAULT_LINUX_SOCKET : & str = "/tmp/com.prime.worker/" ;
19+ const DEFAULT_SOCKET_FILE : & str = "prime-worker/com.prime.worker/metrics.sock" ;
2220
2321pub struct TaskBridge {
24- pub socket_path : String ,
22+ pub socket_path : std :: path :: PathBuf ,
2523 pub metrics_store : Arc < MetricsStore > ,
2624 pub contracts : Option < Contracts < WalletProvider > > ,
2725 pub node_config : Option < Node > ,
@@ -47,27 +45,25 @@ impl TaskBridge {
4745 node_wallet : Option < Wallet > ,
4846 docker_storage_path : String ,
4947 state : Arc < SystemState > ,
50- ) -> Arc < Self > {
48+ ) -> Result < Arc < Self > > {
5149 let path = match socket_path {
52- Some ( path) => path. to_string ( ) ,
50+ Some ( path) => std :: path:: PathBuf :: from ( path ) ,
5351 None => {
54- if cfg ! ( target_os = "macos" ) {
55- format ! ( "{DEFAULT_MACOS_SOCKET}{SOCKET_NAME}" )
56- } else {
57- format ! ( "{DEFAULT_LINUX_SOCKET}{SOCKET_NAME}" )
58- }
52+ let path =
53+ homedir:: my_home ( ) ?. ok_or ( anyhow:: anyhow!( "failed to get home directory" ) ) ?;
54+ path. join ( DEFAULT_SOCKET_FILE )
5955 }
6056 } ;
6157
62- Arc :: new ( Self {
58+ Ok ( Arc :: new ( Self {
6359 socket_path : path,
6460 metrics_store,
6561 contracts,
6662 node_config,
6763 node_wallet,
6864 docker_storage_path,
6965 state,
70- } )
66+ } ) )
7167 }
7268
7369 async fn handle_metric ( self : Arc < Self > , input : & MetricInput ) -> Result < ( ) > {
@@ -357,7 +353,8 @@ mod tests {
357353 None ,
358354 "test_storage_path" . to_string ( ) ,
359355 state,
360- ) ;
356+ )
357+ . unwrap ( ) ;
361358
362359 // Run the bridge in background
363360 let bridge_handle = tokio:: spawn ( async move { bridge. run ( ) . await } ) ;
@@ -388,7 +385,8 @@ mod tests {
388385 None ,
389386 "test_storage_path" . to_string ( ) ,
390387 state,
391- ) ;
388+ )
389+ . unwrap ( ) ;
392390
393391 // Run bridge in background
394392 let bridge_handle = tokio:: spawn ( async move { bridge. run ( ) . await } ) ;
@@ -421,7 +419,8 @@ mod tests {
421419 None ,
422420 "test_storage_path" . to_string ( ) ,
423421 state,
424- ) ;
422+ )
423+ . unwrap ( ) ;
425424
426425 let bridge_handle = tokio:: spawn ( async move { bridge. run ( ) . await } ) ;
427426
@@ -468,7 +467,8 @@ mod tests {
468467 None ,
469468 "test_storage_path" . to_string ( ) ,
470469 state,
471- ) ;
470+ )
471+ . unwrap ( ) ;
472472
473473 let bridge_handle = tokio:: spawn ( async move { bridge. run ( ) . await } ) ;
474474
@@ -515,7 +515,8 @@ mod tests {
515515 None ,
516516 "test_storage_path" . to_string ( ) ,
517517 state,
518- ) ;
518+ )
519+ . unwrap ( ) ;
519520
520521 let bridge_handle = tokio:: spawn ( async move { bridge. run ( ) . await } ) ;
521522
0 commit comments