8000 fix(autoload/tar.vim): Not preserving pwd by michelesr · Pull Request #17339 · vim/vim · GitHub
[go: up one dir, main page]

Skip to content

fix(autoload/tar.vim): Not preserving pwd #17339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

michelesr
Copy link
Contributor

Fix #17334

@@ -432,11 +433,14 @@ if v:shell_error != 0
set nomod

let &report= repkeep
exe "cd ".pwdkeep
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exe "cd ".pwdkeep
cd -

and then get rid of pwdkeep var

Copy link
Contributor
@habamax habamax May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be lcd everywhere then?

Like:

" attempt to change to the indicated directory
try
   exe "lcd ".fnameescape(tmpdir)
...

Copy link
Contributor
@habamax habamax May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisbra cd - might not do what is expected if v:shell_error:

if v:shell_error != 0
   cd ..
   call s:Rmdir("_ZIPVIM_")
   exe "cd ".fnameescape(curdir)
   echohl Error | echo "***error*** (tar#Read) sorry, unable to open or extract ".tarfile." with ".fname | echohl None
  endif

It would change it back to the original path and then cd - would change it back to the tmpdir.

So I would use exe "cd " .. fnameescape(curdir) instead of cd -.

And use lcd everywhere too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is unfortunate we can't easily use defer with old lambdas:

" attempt to change to the indicated directory
try 
 exe "lcd ".fnameescape(tmpdir)
 defer {-> lcd -}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes makes sense. We could potentially also use a try/catch/finally block.

@@ -569,6 +573,7 @@ fun! tar#Write(fname)
setlocal nomod

let &report= repkeep
exe "cd ".pwdkeep
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -280,6 +280,7 @@ endfun
" ---------------------------------------------------------------------
" tar#Read: {{{2
fun! tar#Read(fname,mode)
let pwdkeep = getcwd()
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And while we are here, it probably would be good to remove this strong expression.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

endfun

" ---------------------------------------------------------------------
" tar#Write: {{{2
fun! tar#Write(fname)
let pwdkeep = getcwd()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@habamax while in tar#Read we can use curdir because is set to the original working directory, in tar#Write it seems to be set to a temporary directory instead, e.g. /tmp/vemgadL/1 (tried this in Linux Alpine), so we probably still need a separate variable to restore the original pwd?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's because in tar#Read

let b:curdir= tmpdir
b:curdir is set to the temporary directory, and in tar#Write
let curdir= b:curdir
curdir is set to b:curdir that still points to the temporary directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So while it might not be DRY, having a dedicated variable, like pwdkeep, at least in tar#Write, seems the easiest way to restore the original pwd, and at that stage might as well use it in tar#Read for consistency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For tar#Write for sure we need another var to keep&restore current directory.

It is not clear what problem OG author had, but apparently there was something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there are test cases, simple grep for tar#Write shows nothing :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the original author meant to do goes beyond my understanding. I'll keep the pwdkeep variable for tar#Write while implementing the other suggested changes.

@michelesr
Copy link
Contributor Author

Thanks for the feedback. I've implemented the suggested changes.

@michelesr michelesr requested review from habamax and chrisbra May 19, 2025 12:51
@chrisbra
Copy link
Member

thanks. Should be fine to include now. Perhaps we can create a tar test in the future. Should be relatively straight forward by using test_plugin_zip.vim as an example

@chrisbra chrisbra closed this in 719ec0f May 19, 2025
clason added a commit to clason/neovim that referenced this pull request May 19, 2025
…g 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

vim/vim@719ec0f

Co-authored-by: Michele Sorcinelli <michelesr@autistici.org>
clason added a commit to neovim/neovim that referenced this pull request May 20, 2025
…g 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

vim/vim@719ec0f

Co-authored-by: Michele Sorcinelli <michelesr@autistici.org>
lewis6991 pushed a commit to lewis6991/neovim that referenced this pull request May 20, 2025
…g 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

vim/vim@719ec0f

Co-authored-by: Michele Sorcinelli <michelesr@autistici.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Working directory changes when opening a file inside a tarball
3 participants
0