Skip to content

fix(#914): remove existence check before create-file, rename-file, harden clobbered buffer renaming #1977

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 2 commits into from

Conversation

alex-courtis
Copy link
Member

fixes #914

@gegoune
Copy link
Collaborator

gegoune commented Feb 7, 2023

I hope that it will not bite back. :)

@alex-courtis
Copy link
Member Author

Rename failure case OK:
[NvimTree] "Cannot rename /home/alex/914/File.txt -> /home/alex/914/inexistent/File.txt: ENOENT: no such file or directory: /home/alex/914/File.txt -> /home/alex/914/inexistent/File.txt"

Rename when both buffers open failed:

E5108: Error executing lua: ...t-dev/site/pack/packer/start/dev/lua/nvim-tree/utils.lua:166: Failed to rename buffer
stack traceback:
        [C]: in function 'nvim_buf_set_name'
        ...t-dev/site/pack/packer/start/dev/lua/nvim-tree/utils.lua:166: in function 'rename_loaded_buffers'
        ...acker/start/dev/lua/nvim-tree/actions/fs/rename-file.lua:25: in function 'rename'
        ...acker/start/dev/lua/nvim-tree/actions/fs/rename-file.lua:75: in function 'on_confirm'
        /usr/share/nvim/runtime/lua/vim/ui.lua:93: in function 'input'
        ...acker/start/dev/lua/nvim-tree/actions/fs/rename-file.lua:69: in function 'handle_tree_actions'
        ...pack/packer/start/dev/lua/nvim-tree/actions/dispatch.lua:123: in function 'dispatch'
        ...ite/pack/packer/start/dev/lua/nvim-tree/actions/init.lua:273: in function <...ite/pack/packer/start/dev/lua/nvim-tree/actions/init.lua:272>

Create clobbers OK, although vim will need to reload the external changes if the buffer is open.

@alex-courtis
Copy link
Member Author

That was a can of worms. Resolved an existing paste bug.

Test cases:

Rename:

  • no files open
  • source file open - buffer renamed

Rename Clobber:

  • no files open
  • source file open - buffer renamed
  • dest file open - source buffer remains loaded, working as per paste clobber
  • both files open - source buffer remains loaded, working as per paste clobber

Paste:

  • no files open
  • source file open - buffer renamed

Paste Clobber

  • no files open
  • source file open - buffer renamed
  • dest file open - source buffer remains loaded, existing behaviour
  • both files open - source buffer remains loaded, previously threw exception

Tested buffers loaded with absolute and relative paths.

local exact_match = buf_name == old_path
local child_match = (
buf_name:sub(1, #old_path) == old_path and buf_name:sub(#old_path + 1, #old_path + 1) == path_separator
)
Copy link
Member Author

Choose a reason for hiding this comment

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

All callers use absolute paths hence this fuzzy matching can be removed.

@alex-courtis alex-courtis changed the title fix(#914): remove existence check before create-file, rename-file fix(#914): remove existence check before create-file, rename-file, harden clobbered buffer renaming Feb 7, 2023
@alex-courtis
Copy link
Member Author

I was tempted to remove the existence checks from paste, however they can be useful and nobody has reported issues.

@alex-courtis
Copy link
Member Author

This was a failure; trying a simpler approach: #1988

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.

Case sensitive rename not possible (cannot rename)
2 participants