vim-patch:719ec0f: runtime(tar): preserve pwd when reading and writing tar files

While at it, use `:lcd` to temporarily set the window local directory
instead of `:cd` for the global working directory.

fixes: vim/vim#17334
closes: vim/vim#17339

719ec0fe15

Co-authored-by: Michele Sorcinelli <michelesr@autistici.org>
This commit is contained in:
Christian Clason
2025-05-19 20:46:33 +02:00
committed by Christian Clason
parent 14631e2264
commit 849e24f3cd

View File

@ -307,10 +307,10 @@ fun! tar#Read(fname,mode)
" attempt to change to the indicated directory
try
exe "cd ".fnameescape(tmpdir)
exe "lcd ".fnameescape(tmpdir)
catch /^Vim\%((\a\+)\)\=:E344/
redraw!
echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None
echohl Error | echo "***error*** (tar#Write) cannot lcd to temporary directory" | Echohl None
let &report= repkeep
return
endtry
@ -320,7 +320,7 @@ fun! tar#Read(fname,mode)
call s:Rmdir("_ZIPVIM_")
endif
call mkdir("_ZIPVIM_")
cd _ZIPVIM_
lcd _ZIPVIM_
if has("win32unix") && executable("cygpath")
" assuming cygwin
@ -418,9 +418,9 @@ fun! tar#Read(fname,mode)
redraw!
if v:shell_error != 0
cd ..
lcd ..
call s:Rmdir("_ZIPVIM_")
exe "cd ".fnameescape(curdir)
exe "lcd ".fnameescape(curdir)
echohl Error | echo "***error*** (tar#Read) sorry, unable to open or extract ".tarfile." with ".fname | echohl None
endif
@ -437,14 +437,16 @@ if v:shell_error != 0
set nomod
let &report= repkeep
exe "lcd ".fnameescape(curdir)
silent exe "file tarfile::".escape_file
endfun
" ---------------------------------------------------------------------
" tar#Write: {{{2
fun! tar#Write(fname)
let pwdkeep= getcwd()
let repkeep= &report
set report=10
" temporary buffer variable workaround because too fucking tired. but it works now
let curdir= b:curdir
let tmpdir= b:tmpdir
@ -567,9 +569,9 @@ fun! tar#Write(fname)
endif
" cleanup and restore current directory
cd ..
lcd ..
call s:Rmdir("_ZIPVIM_")
exe "cd ".fnameescape(curdir)
exe "lcd ".fnameescape(pwdkeep)
setlocal nomod
let &report= repkeep