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
26
26
foundry-config.workspace = true
27
27
foundry-evm.workspace = true
28
28
29
+ tempfile.workspace = true
30
+
29
31
solar.workspace = true
30
32
31
33
alloy-dyn-abi = { workspace = true , features = [" arbitrary" ] }
Original file line number Diff line number Diff line change @@ -27,10 +27,12 @@ use solar::{
27
27
} ;
28
28
use std:: {
29
29
borrow:: Cow ,
30
+ io:: Write ,
30
31
ops:: ControlFlow ,
31
32
path:: { Path , PathBuf } ,
32
33
process:: Command ,
33
34
} ;
35
+ use tempfile:: Builder ;
34
36
use tracing:: debug;
35
37
use yansi:: Paint ;
36
38
@@ -488,20 +490,25 @@ impl ChiselDispatcher {
488
490
489
491
pub ( crate ) async fn edit_session ( & mut self ) -> Result < ( ) > {
490
492
// 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 ( ) )
493
500
. wrap_err ( "Could not write to temporary file" ) ?;
494
501
495
502
// open the temp file with the editor
496
503
let editor = std:: env:: var ( "EDITOR" ) . unwrap_or_else ( |_| "vim" . to_string ( ) ) ;
497
504
let mut cmd = Command :: new ( editor) ;
498
- cmd. arg ( & tmp) ;
505
+ cmd. arg ( tmp. path ( ) ) ;
499
506
let st = cmd. status ( ) ?;
500
507
if !st. success ( ) {
501
508
eyre:: bail!( "Editor exited with {st}" ) ;
502
509
}
503
510
504
- let edited_code = std:: fs:: read_to_string ( tmp) ?;
511
+ let edited_code = std:: fs:: read_to_string ( tmp. path ( ) ) ?;
505
512
let mut new_source = self . source ( ) . clone ( ) ;
506
513
new_source. clear_run ( ) ;
507
514
new_source. add_run_code ( & edited_code) ;
You can’t perform that action at this time.
0 commit comments