File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ foundry-compilers.workspace = true
2626foundry-config.workspace = true
2727foundry-evm.workspace = true
2828
29+ tempfile.workspace = true
30+
2931solar.workspace = true
3032
3133alloy-dyn-abi = { workspace = true , features = [" arbitrary" ] }
Original file line number Diff line number Diff line change @@ -27,10 +27,12 @@ use solar::{
2727} ;
2828use std:: {
2929 borrow:: Cow ,
30+ io:: Write ,
3031 ops:: ControlFlow ,
3132 path:: { Path , PathBuf } ,
3233 process:: Command ,
3334} ;
35+ use tempfile:: Builder ;
3436use tracing:: debug;
3537use yansi:: Paint ;
3638
@@ -488,20 +490,25 @@ impl ChiselDispatcher {
488490
489491 pub ( crate ) async fn edit_session ( & mut self ) -> Result < ( ) > {
490492 // create a temp file with the content of the run code
491- let tmp = std:: env:: temp_dir ( ) . join ( "chisel-tmp.sol" ) ;
492- std:: fs:: write ( & tmp, self . source ( ) . run_code . as_bytes ( ) )
493+ let mut tmp = Builder :: new ( )
494+ . prefix ( "chisel-" )
495+ . suffix ( ".sol" )
496+ . tempfile ( )
497+ . wrap_err ( "Could not create temporary file" ) ?;
498+ tmp. as_file_mut ( )
499+ . write_all ( self . source ( ) . run_code . as_bytes ( ) )
493500 . wrap_err ( "Could not write to temporary file" ) ?;
494501
495502 // open the temp file with the editor
496503 let editor = std:: env:: var ( "EDITOR" ) . unwrap_or_else ( |_| "vim" . to_string ( ) ) ;
497504 let mut cmd = Command :: new ( editor) ;
498- cmd. arg ( & tmp) ;
505+ cmd. arg ( tmp. path ( ) ) ;
499506 let st = cmd. status ( ) ?;
500507 if !st. success ( ) {
501508 eyre:: bail!( "Editor exited with {st}" ) ;
502509 }
503510
504- let edited_code = std:: fs:: read_to_string ( tmp) ?;
511+ let edited_code = std:: fs:: read_to_string ( tmp. path ( ) ) ?;
505512 let mut new_source = self . source ( ) . clone ( ) ;
506513 new_source. clear_run ( ) ;
507514 new_source. add_run_code ( & edited_code) ;
You can’t perform that action at this time.
0 commit comments