To: vim_dev@googlegroups.com Subject: Patch 8.2.1340 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1340 Problem: Some tests fail on Cirrus CI and/or with FreeBSD. Solution: Make 'backupskip' empty. Do not run tests as root. Check for directory when using viminfo. (Ozaki Kiichi, closes #6596) Files: .cirrus.yml, src/testdir/test_backup.vim, src/testdir/test_edit.vim, src/testdir/test_viminfo.vim, src/testdir/test_writefile.vim, src/viminfo.c *** ../vim-8.2.1339/.cirrus.yml 2020-05-06 22:25:01.817277680 +0200 --- .cirrus.yml 2020-08-01 16:00:56.603701845 +0200 *************** *** 11,16 **** - NPROC=$(getconf _NPROCESSORS_ONLN) - ./configure --with-features=${FEATURES} - make -j${NPROC} - - src/vim --version test_script: ! - make test --- 11,19 ---- - NPROC=$(getconf _NPROCESSORS_ONLN) - ./configure --with-features=${FEATURES} - make -j${NPROC} test_script: ! - src/vim --version ! # run tests as user "cirrus" instead of root ! - pw useradd cirrus -m ! - chown -R cirrus:cirrus . ! - sudo -u cirrus make test *** ../vim-8.2.1339/src/testdir/test_backup.vim 2020-06-11 19:22:40.144625523 +0200 --- src/testdir/test_backup.vim 2020-08-01 15:59:05.724188158 +0200 *************** *** 19,24 **** --- 19,40 ---- call delete('Xbackup.txt~') endfunc + func Test_backup_backupskip() + set backup backupdir=. backupskip=*.txt + new + call setline(1, ['line1', 'line2']) + :f Xbackup.txt + :w! Xbackup.txt + " backup file is only created after + " writing a second time (before overwriting) + :w! Xbackup.txt + call assert_false(filereadable('Xbackup.txt~')) + bw! + set backup&vim backupdir&vim backupskip&vim + call delete('Xbackup.txt') + call delete('Xbackup.txt~') + endfunc + func Test_backup2() set backup backupdir=.// backupskip= new *************** *** 30,36 **** :w! Xbackup.txt sp *Xbackup.txt~ call assert_equal(['line1', 'line2', 'line3'], getline(1,'$')) ! let f=expand('%') call assert_match('%testdir%Xbackup.txt\~', f) bw! bw! --- 46,52 ---- :w! Xbackup.txt sp *Xbackup.txt~ call assert_equal(['line1', 'line2', 'line3'], getline(1,'$')) ! let f = expand('%') call assert_match('%testdir%Xbackup.txt\~', f) bw! bw! *************** *** 50,56 **** :w! Xbackup.txt sp *Xbackup.txt~ call assert_equal(['line1', 'line2', 'line3'], getline(1,'$')) ! let f=expand('%') call assert_match('%testdir%Xbackup.txt\~', f) bw! bw! --- 66,72 ---- :w! Xbackup.txt sp *Xbackup.txt~ call assert_equal(['line1', 'line2', 'line3'], getline(1,'$')) ! let f = expand('%') call assert_match('%testdir%Xbackup.txt\~', f) bw! bw! *************** *** 61,74 **** " Test for using a non-existing directory as a backup directory func Test_non_existing_backupdir() ! CheckNotBSD ! let save_backup = &backupdir ! set backupdir=./non_existing_dir call writefile(['line1'], 'Xfile') new Xfile - " TODO: write doesn't fail in Cirrus FreeBSD CI test call assert_fails('write', 'E510:') ! let &backupdir = save_backup call delete('Xfile') endfunc --- 77,87 ---- " Test for using a non-existing directory as a backup directory func Test_non_existing_backupdir() ! set backupdir=./non_existing_dir backupskip= call writefile(['line1'], 'Xfile') new Xfile call assert_fails('write', 'E510:') ! set backupdir&vim backupskip&vim call delete('Xfile') endfunc *** ../vim-8.2.1339/src/testdir/test_edit.vim 2020-06-20 16:05:29.012185251 +0200 --- src/testdir/test_edit.vim 2020-08-01 15:59:05.724188158 +0200 *************** *** 1682,1688 **** " Test for editing a file without read permission func Test_edit_file_no_read_perm() CheckUnix - CheckNotBSD call writefile(['one', 'two'], 'Xfile') call setfperm('Xfile', '-w-------') new --- 1682,1687 ---- *** ../vim-8.2.1339/src/testdir/test_viminfo.vim 2020-07-11 22:14:54.318422203 +0200 --- src/testdir/test_viminfo.vim 2020-08-01 15:59:05.724188158 +0200 *************** *** 807,813 **** " Try to write the viminfo to a directory call mkdir('Xdir') ! call assert_fails('wviminfo Xdir', 'E886:') call delete('Xdir', 'rf') endfunc --- 807,813 ---- " Try to write the viminfo to a directory call mkdir('Xdir') ! call assert_fails('wviminfo Xdir', 'E137:') call delete('Xdir', 'rf') endfunc *** ../vim-8.2.1339/src/testdir/test_writefile.vim 2020-07-29 16:08:13.457861141 +0200 --- src/testdir/test_writefile.vim 2020-08-01 15:59:05.724188158 +0200 *************** *** 136,144 **** endfunc func Test_writefile_sync_dev_stdout() ! if !has('unix') ! return ! endif if filewritable('/dev/stdout') " Just check that this doesn't cause an error. call writefile(['one'], '/dev/stdout') --- 136,142 ---- endfunc func Test_writefile_sync_dev_stdout() ! CheckUnix if filewritable('/dev/stdout') " Just check that this doesn't cause an error. call writefile(['one'], '/dev/stdout') *************** *** 371,383 **** " Test for writing to a readonly file func Test_write_readonly() - " In Cirrus-CI, the freebsd tests are run under a root account. So this test - " doesn't fail. - CheckNotBSD call writefile([], 'Xfile') call setfperm('Xfile', "r--------") edit Xfile ! set noreadonly call assert_fails('write', 'E505:') let save_cpo = &cpo set cpo+=W --- 369,378 ---- " Test for writing to a readonly file func Test_write_readonly() call writefile([], 'Xfile') call setfperm('Xfile', "r--------") edit Xfile ! set noreadonly backupskip= call assert_fails('write', 'E505:') let save_cpo = &cpo set cpo+=W *************** *** 386,422 **** call setline(1, ['line1']) write! call assert_equal(['line1'], readfile('Xfile')) call delete('Xfile') endfunc " Test for 'patchmode' func Test_patchmode() - CheckNotBSD call writefile(['one'], 'Xfile') ! set patchmode=.orig nobackup writebackup new Xfile call setline(1, 'two') " first write should create the .orig file write - " TODO: Xfile.orig is not created in Cirrus FreeBSD CI test call assert_equal(['one'], readfile('Xfile.orig')) call setline(1, 'three') " subsequent writes should not create/modify the .orig file write call assert_equal(['one'], readfile('Xfile.orig')) ! set patchmode& backup& writebackup& call delete('Xfile') call delete('Xfile.orig') endfunc " Test for writing to a file in a readonly directory func Test_write_readonly_dir() ! if !has('unix') || has('bsd') ! " On MS-Windows, modifying files in a read-only directory is allowed. ! " In Cirrus-CI for Freebsd, tests are run under a root account where ! " modifying files in a read-only directory are allowed. ! return ! endif call mkdir('Xdir') call writefile(['one'], 'Xdir/Xfile1') call setfperm('Xdir', 'r-xr--r--') --- 381,412 ---- call setline(1, ['line1']) write! call assert_equal(['line1'], readfile('Xfile')) + set backupskip& call delete('Xfile') endfunc " Test for 'patchmode' func Test_patchmode() call writefile(['one'], 'Xfile') ! set patchmode=.orig nobackup backupskip= writebackup new Xfile call setline(1, 'two') " first write should create the .orig file write call assert_equal(['one'], readfile('Xfile.orig')) call setline(1, 'three') " subsequent writes should not create/modify the .orig file write call assert_equal(['one'], readfile('Xfile.orig')) ! set patchmode& backup& backupskip& writebackup& call delete('Xfile') call delete('Xfile.orig') endfunc " Test for writing to a file in a readonly directory func Test_write_readonly_dir() ! " On MS-Windows, modifying files in a read-only directory is allowed. ! CheckUnix call mkdir('Xdir') call writefile(['one'], 'Xdir/Xfile1') call setfperm('Xdir', 'r-xr--r--') *************** *** 426,437 **** call assert_fails('write', 'E212:') " try to create a backup file in the directory edit! Xdir/Xfile1 ! set backupdir=./Xdir set patchmode=.orig call assert_fails('write', 'E509:') call setfperm('Xdir', 'rwxr--r--') call delete('Xdir', 'rf') ! set backupdir& patchmode& endfunc " Test for writing a file using invalid file encoding --- 416,427 ---- call assert_fails('write', 'E212:') " try to create a backup file in the directory edit! Xdir/Xfile1 ! set backupdir=./Xdir backupskip= set patchmode=.orig call assert_fails('write', 'E509:') call setfperm('Xdir', 'rwxr--r--') call delete('Xdir', 'rf') ! set backupdir& backupskip& patchmode& endfunc " Test for writing a file using invalid file encoding *** ../vim-8.2.1339/src/viminfo.c 2020-06-07 16:08:03.660925978 +0200 --- src/viminfo.c 2020-08-01 15:59:05.724188158 +0200 *************** *** 3007,3012 **** --- 3007,3013 ---- { FILE *fp; char_u *fname; + stat_T st; // mch_stat() of existing viminfo file if (no_viminfo()) return FAIL; *************** *** 3031,3036 **** --- 3032,3042 ---- vim_free(fname); if (fp == NULL) return FAIL; + if (mch_fstat(fileno(fp), &st) < 0 || S_ISDIR(st.st_mode)) + { + fclose(fp); + return FAIL; + } viminfo_errcnt = 0; do_viminfo(fp, NULL, flags); *************** *** 3054,3065 **** FILE *fp_out = NULL; // output viminfo file char_u *tempname = NULL; // name of temp viminfo file stat_T st_new; // mch_stat() of potential new file #if defined(UNIX) || defined(VMS) mode_t umask_save; #endif #ifdef UNIX int shortname = FALSE; // use 8.3 file name - stat_T st_old; // mch_stat() of existing viminfo file #endif #ifdef MSWIN int hidden = FALSE; --- 3060,3071 ---- FILE *fp_out = NULL; // output viminfo file char_u *tempname = NULL; // name of temp viminfo file stat_T st_new; // mch_stat() of potential new file + stat_T st_old; // mch_stat() of existing viminfo file #if defined(UNIX) || defined(VMS) mode_t umask_save; #endif #ifdef UNIX int shortname = FALSE; // use 8.3 file name #endif #ifdef MSWIN int hidden = FALSE; *************** *** 3097,3116 **** // write the new viminfo into, in the same directory as the // existing viminfo file, which will be renamed once all writing is // successful. #ifdef UNIX ! // For Unix we check the owner of the file. It's not very nice to ! // overwrite a user's viminfo file after a "su root", with a ! // viminfo file that the user can't read. ! st_old.st_dev = (dev_t)0; ! st_old.st_ino = 0; ! st_old.st_mode = 0600; ! if (mch_stat((char *)fname, &st_old) == 0 ! && getuid() != ROOT_UID ! && !(st_old.st_uid == getuid() ! ? (st_old.st_mode & 0200) ! : (st_old.st_gid == getgid() ! ? (st_old.st_mode & 0020) ! : (st_old.st_mode & 0002)))) { int tt = msg_didany; --- 3103,3122 ---- // write the new viminfo into, in the same directory as the // existing viminfo file, which will be renamed once all writing is // successful. + if (mch_fstat(fileno(fp_in), &st_old) < 0 + || S_ISDIR(st_old.st_mode) #ifdef UNIX ! // For Unix we check the owner of the file. It's not very nice ! // to overwrite a user's viminfo file after a "su root", with a ! // viminfo file that the user can't read. ! || (getuid() != ROOT_UID ! && !(st_old.st_uid == getuid() ! ? (st_old.st_mode & 0200) ! : (st_old.st_gid == getgid() ! ? (st_old.st_mode & 0020) ! : (st_old.st_mode & 0002)))) ! #endif ! ) { int tt = msg_didany; *************** *** 3120,3126 **** fclose(fp_in); goto end; } - #endif #ifdef MSWIN // Get the file attributes of the existing viminfo file. hidden = mch_ishidden(fname); --- 3126,3131 ---- *** ../vim-8.2.1339/src/version.c 2020-08-01 15:53:16.517720156 +0200 --- src/version.c 2020-08-01 15:59:40.264036663 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1340, /**/ -- hundred-and-one symptoms of being an internet addict: 94. Now admit it... How many of you have made "modem noises" into the phone just to see if it was possible? :-) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///