commit 849e24f3cdb332616035422615b784e3bb476e35
parent 14631e2264b12daadb5307c03c6bad33c151d511
Author: Christian Clason <c.clason@uni-graz.at>
Date: Mon, 19 May 2025 20:46:33 +0200
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
https://github.com/vim/vim/commit/719ec0fe154e321bf7cf2cb2f93e8aa30036b87e
Co-authored-by: Michele Sorcinelli <michelesr@autistici.org>
Diffstat:
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/runtime/autoload/tar.vim b/runtime/autoload/tar.vim
@@ -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