Skip to content

Commit 641ad6c

Browse files
committed
patch 7.4.2301
Problem: MS-Windows: some files remain after testing. Solution: Close the channel output file. Wait for the file handle to be closed before deleting the file.
1 parent 5c80908 commit 641ad6c

3 files changed

Lines changed: 33 additions & 21 deletions

File tree

src/os_win32.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5210,11 +5210,9 @@ mch_start_job(char *cmd, job_T *job, jobopt_T *options)
52105210
job->jv_job_object = jo;
52115211
job->jv_status = JOB_STARTED;
52125212

5213-
if (!use_file_for_in)
5214-
CloseHandle(ifd[0]);
5215-
if (!use_file_for_out)
5216-
CloseHandle(ofd[1]);
5217-
if (!use_out_for_err && !use_file_for_err)
5213+
CloseHandle(ifd[0]);
5214+
CloseHandle(ofd[1]);
5215+
if (!use_out_for_err && !use_null_for_err)
52185216
CloseHandle(efd[1]);
52195217

52205218
job->jv_channel = channel;

src/testdir/test_channel.vim

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -533,27 +533,39 @@ func Test_nl_err_to_out_pipe()
533533
call assert_equal(1, found_send)
534534
call assert_equal(1, found_recv)
535535
call assert_equal(1, found_stop)
536+
" On MS-Windows need to sleep for a moment to be able to delete the file.
537+
sleep 10m
536538
call delete('Xlog')
537539
endtry
538540
endfunc
539541

542+
func Stop_g_job()
543+
call job_stop(g:job)
544+
if has('win32')
545+
" On MS-Windows the server must close the file handle before we are able
546+
" to delete the file.
547+
call WaitFor('job_status(g:job) == "dead"')
548+
sleep 10m
549+
endif
550+
endfunc
551+
540552
func Test_nl_read_file()
541553
if !has('job')
542554
return
543555
endif
544556
call ch_log('Test_nl_read_file()')
545557
call writefile(['echo something', 'echoerr wrong', 'double this'], 'Xinput')
546-
let job = job_start(s:python . " test_channel_pipe.py",
558+
let g:job = job_start(s:python . " test_channel_pipe.py",
547559
\ {'in_io': 'file', 'in_name': 'Xinput'})
548-
call assert_equal("run", job_status(job))
560+
call assert_equal("run", job_status(g:job))
549561
try
550-
let handle = job_getchannel(job)
562+
let handle = job_getchannel(g:job)
551563
call assert_equal("something", ch_readraw(handle))
552564
call assert_equal("wrong", ch_readraw(handle, {'part': 'err'}))
553565
call assert_equal("this", ch_readraw(handle))
554566
call assert_equal("AND this", ch_readraw(handle))
555567
finally
556-
call job_stop(job)
568+
call Stop_g_job()
557569
call delete('Xinput')
558570
endtry
559571
endfunc
@@ -563,18 +575,18 @@ func Test_nl_write_out_file()
563575
return
564576
endif
565577
call ch_log('Test_nl_write_out_file()')
566-
let job = job_start(s:python . " test_channel_pipe.py",
578+
let g:job = job_start(s:python . " test_channel_pipe.py",
567579
\ {'out_io': 'file', 'out_name': 'Xoutput'})
568-
call assert_equal("run", job_status(job))
580+
call assert_equal("run", job_status(g:job))
569581
try
570-
let handle = job_getchannel(job)
582+
let handle = job_getchannel(g:job)
571583
call ch_sendraw(handle, "echo line one\n")
572584
call ch_sendraw(handle, "echo line two\n")
573585
call ch_sendraw(handle, "double this\n")
574586
call WaitFor('len(readfile("Xoutput")) > 2')
575587
call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))
576588
finally
577-
call job_stop(job)
589+
call Stop_g_job()
578590
call delete('Xoutput')
579591
endtry
580592
endfunc
@@ -584,18 +596,18 @@ func Test_nl_write_err_file()
584596
return
585597
endif
586598
call ch_log('Test_nl_write_err_file()')
587-
let job = job_start(s:python . " test_channel_pipe.py",
599+
let g:job = job_start(s:python . " test_channel_pipe.py",
588600
\ {'err_io': 'file', 'err_name': 'Xoutput'})
589-
call assert_equal("run", job_status(job))
601+
call assert_equal("run", job_status(g:job))
590602
try
591-
let handle = job_getchannel(job)
603+
let handle = job_getchannel(g:job)
592604
call ch_sendraw(handle, "echoerr line one\n")
593605
call ch_sendraw(handle, "echoerr line two\n")
594606
call ch_sendraw(handle, "doubleerr this\n")
595607
call WaitFor('len(readfile("Xoutput")) > 2')
596608
call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))
597609
finally
598-
call job_stop(job)
610+
call Stop_g_job()
599611
call delete('Xoutput')
600612
endtry
601613
endfunc
@@ -605,19 +617,19 @@ func Test_nl_write_both_file()
605617
return
606618
endif
607619
call ch_log('Test_nl_write_both_file()')
608-
let job = job_start(s:python . " test_channel_pipe.py",
620+
let g:job = job_start(s:python . " test_channel_pipe.py",
609621
\ {'out_io': 'file', 'out_name': 'Xoutput', 'err_io': 'out'})
610-
call assert_equal("run", job_status(job))
622+
call assert_equal("run", job_status(g:job))
611623
try
612-
let handle = job_getchannel(job)
624+
let handle = job_getchannel(g:job)
613625
call ch_sendraw(handle, "echoerr line one\n")
614626
call ch_sendraw(handle, "echo line two\n")
615627
call ch_sendraw(handle, "double this\n")
616628
call ch_sendraw(handle, "doubleerr that\n")
617629
call WaitFor('len(readfile("Xoutput")) > 5')
618630
call assert_equal(['line one', 'line two', 'this', 'AND this', 'that', 'AND that'], readfile('Xoutput'))
619631
finally
620-
call job_stop(job)
632+
call Stop_g_job()
621633
call delete('Xoutput')
622634
endtry
623635
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ static char *(features[]) =
763763

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2301,
766768
/**/
767769
2300,
768770
/**/

0 commit comments

Comments
 (0)