Skip to content

Commit

Permalink
Added a check for file already exists and also switched the is_error …
Browse files Browse the repository at this point in the history
…values as they were mismatched
  • Loading branch information
mohamedarish committed Feb 26, 2024
1 parent a7c9efc commit c41be1f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lua/nvim-tree/actions/fs/rename-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,26 @@ function M.rename(node, to)
end

if is_last_path_file and idx == num_nodes then
if utils.file_exists(to) then
notify.warn(err_fmt(notify_from, notify_to, "file already exists"))
return
end

events._dispatch_will_rename_node(node.absolute_path, to)
local success, err = vim.loop.fs_rename(node.absolute_path, to)

if not success then
notify.warn(err_fmt(notify_from, notify_to, err))
is_error = true
break
return
end
elseif not utils.file_exists(path_to_create) then
local success = vim.loop.fs_mkdir(path_to_create, 493)
if not success then
notify.error("Could not create folder " .. notify.render_path(path_to_create))
is_error = true
break
end
is_error = true
is_error = false
end
end

Expand Down

0 comments on commit c41be1f

Please sign in to comment.