Skip to content
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

Deleting a directory containing symlink file will delete all content inside the symlink #3077

Open
ChunHou20c opened this issue Mar 6, 2025 · 1 comment
Labels
bug Something isn't working reproduced Issue confirmed

Comments

@ChunHou20c
Copy link

ChunHou20c commented Mar 6, 2025

Description

If you delete a directory in nvim tree that contain a symlink directory, deletion will fail and then the content inside the symlink actual directory is gone. the symlink itself is still there but the content are gone.

I try to delete the node_modules folder in one of my project within nvim tree trying to clean things up. One of the dependency in my project is a symlink to my local repo:

it looks like this:
| node-modules/
|--- deps-a -> /home/user/dev/deps-a

After that an error occur saying that the deletion of node_modules directory cannot be done, but when I go back to my deps-a directory, everything is gone, even .git is gone.

Neovim version

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1713773202

Operating system and version

Nixos-24.11

Windows variant

No response

nvim-tree version

28eac28

Clean room replication

-- no configuration is needed, default configuration will still cause the same issue so I just paste the original nvt-min.lua here
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup({
    {
      "wbthomason/packer.nvim",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  })
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing nvim-tree and dependencies.")
  vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup({})
end

-- UNCOMMENT this block for diagnostics issues, substituting pattern and cmd as appropriate.
-- Requires diagnostics.enable = true in setup.
--[[
vim.api.nvim_create_autocmd("FileType", {
  pattern = "lua",
  callback = function()
    vim.lsp.start {
      name = "my-luals",
      cmd = { "lua-language-server" },
      root_dir = vim.loop.cwd(),
    }
  end,
})
]]

Steps to reproduce

mkdir testing && cd testing
mkdir first-dir
mkdir dir-to-delete && touch dir-to-delete/dont_delete_me
ln -s $(pwd)/dir-to-delete $(pwd)/first-dir/dir-symlink
nvim -nu /tmp/nvt-min.lua
:NvimTreeOpen

delete first-dir from nvim tree
the file inside dir-to-delete is gone, but the symlink is still there

Expected behavior

the symlink should be be deleted, along with the first-dir, if that is not possible, nothing should had been done. I don't expect it to go into the symlink and delete everything for me

Actual behavior

The content inside the original symlink directory gets deleted.

Image

After trying to delete first-dir, the content inside the symlink is deleted
Image

@ChunHou20c ChunHou20c added the bug Something isn't working label Mar 6, 2025
@alex-courtis
Copy link
Member

Many thanks for the detailed reproducer! Confirmed.

[NvimTree] Could not remove /home/alex/src/nvim-tree/r/3077/testing/testing/first-dir warning on deleting first-dir does indicate that something went very wrong.

@alex-courtis alex-courtis added the reproduced Issue confirmed label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproduced Issue confirmed
Projects
None yet
Development

No branches or pull requests

2 participants