Skip to content

Commit 3d37231

Browse files
committed
runtime(tar): improve the error detection
Do not rely on the fact, that the last line matches warning, error, inappropriate or unrecognized to determine if an error occurred. It could also be a file, contains such a keyword. So make the error detection slightly more strict and only assume an error occured, if in addition to those 4 keywords, also a space matches (this assumes the error message contains a space), which luckily on Unix not many files match by default. The whole if condition seems however slightly dubious. In case an error happened, this would probably already be caught in the previous if statement, since this checks for the return code of the tar program. There may however be tar implementations, that do not set the exit code for some kind of error (but print an error message)? But let's keep this check for now, not many people have noticed this behaviour until now, so it seems to work reasonably well anyhow. related: #6425 fixes: #13489 Signed-off-by: Christian Brabandt <[email protected]>
1 parent da4e433 commit 3d37231

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

runtime/autoload/tar.vim

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" tar.vim: Handles browsing tarfiles
22
" AUTOLOAD PORTION
3-
" Date: Jan 07, 2020
4-
" Version: 32
3+
" Date: Nov 05, 2023
4+
" Version: 32a (with modifications from the Vim Project)
55
" Maintainer: Charles E Campbell <[email protected]>
66
" License: Vim License (see vim's :help license)
77
"
@@ -22,7 +22,7 @@
2222
if &cp || exists("g:loaded_tar")
2323
finish
2424
endif
25-
let g:loaded_tar= "v32"
25+
let g:loaded_tar= "v32a"
2626
if v:version < 702
2727
echohl WarningMsg
2828
echo "***warning*** this version of tar needs vim 7.2"
@@ -208,7 +208,16 @@ fun! tar#Browse(tarfile)
208208
" call Dret("tar#Browse : a:tarfile<".a:tarfile.">")
209209
return
210210
endif
211-
if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~# '\c\%(warning\|error\|inappropriate\|unrecognized\)')
211+
" If there was an error message, the last line probably matches some keywords but
212+
" should also contain whitespace for readability. Make sure not to match a
213+
" filename that contains the keyword (error/warning/unrecognized/inappropriate, etc)
214+
"
215+
" FIXME:is this actually necessary? In case of an error, we should probably
216+
" have noticed in the if statement above since tar should have exited
217+
" with a non-zero exit code.
218+
if line("$") == curlast || ( line("$") == (curlast + 1) &&
219+
\ getline("$") =~# '\c\<\%(warning\|error\|inappropriate\|unrecognized\)\>' &&
220+
\ getline("$") =~ '\s' )
212221
redraw!
213222
echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None
214223
keepj sil! %d

0 commit comments

Comments
 (0)