File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
helix-term/tests/test/commands Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -370,6 +370,33 @@ async fn test_write_scratch_to_new_path() -> anyhow::Result<()> {
370370 Ok ( ( ) )
371371}
372372
373+ #[ tokio:: test( flavor = "multi_thread" ) ]
374+ async fn test_write_scratch_to_new_path_force_creates_file ( ) -> anyhow:: Result < ( ) > {
375+ let dir = tempfile:: tempdir ( ) ?;
376+ let new_path = dir. path ( ) . join ( "new-file.txt" ) ;
377+
378+ test_key_sequence (
379+ & mut AppBuilder :: new ( ) . build ( ) ?,
380+ Some ( format ! ( "ihello<esc>:w! {}<ret>" , new_path. to_string_lossy( ) ) . as_ref ( ) ) ,
381+ Some ( & |app| {
382+ assert ! ( !app. editor. is_err( ) ) ;
383+
384+ let mut docs: Vec < _ > = app. editor . documents ( ) . collect ( ) ;
385+ assert_eq ! ( 1 , docs. len( ) ) ;
386+
387+ let doc = docs. pop ( ) . unwrap ( ) ;
388+ assert_eq ! ( Some ( & path:: normalize( & new_path) ) , doc. path( ) ) ;
389+ } ) ,
390+ false ,
391+ )
392+ . await ?;
393+
394+ let file_content = std:: fs:: read_to_string ( & new_path) ?;
395+ assert_eq ! ( file_content, LineFeedHandling :: Native . apply( "hello" ) ) ;
396+
397+ Ok ( ( ) )
398+ }
399+
373400#[ tokio:: test( flavor = "multi_thread" ) ]
374401async fn test_write_scratch_no_path_fails ( ) -> anyhow:: Result < ( ) > {
375402 helpers:: test_key_sequence_with_input_text (
Original file line number Diff line number Diff line change @@ -1035,7 +1035,11 @@ impl Document {
10351035
10361036 // Assume it is a hardlink to prevent data loss if the metadata cant be read (e.g. on certain Windows configurations)
10371037 let is_hardlink = helix_stdx:: faccess:: hardlink_count ( & write_path) . unwrap_or ( 2 ) > 1 ;
1038- let is_symlink = tokio:: fs:: symlink_metadata ( & write_path) . await ?. is_symlink ( ) ;
1038+ let is_symlink = match tokio:: fs:: symlink_metadata ( & write_path) . await {
1039+ Ok ( meta) => meta. is_symlink ( ) ,
1040+ Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => false ,
1041+ Err ( err) => return Err ( err. into ( ) ) ,
1042+ } ;
10391043 let must_copy = is_hardlink || is_symlink;
10401044 let backup = if path. exists ( ) && atomic_save {
10411045 let path_ = write_path. clone ( ) ;
You can’t perform that action at this time.
0 commit comments