fix: remove redundant file existence check in create file operation (#1936)
This commit is contained in:
parent
96506fee49
commit
16f2806d59
@ -18,21 +18,6 @@ local function create_and_notify(file)
|
|||||||
events._dispatch_file_created(file)
|
events._dispatch_file_created(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_file(file)
|
|
||||||
if utils.file_exists(file) then
|
|
||||||
local prompt_select = "Overwrite " .. file .. " ?"
|
|
||||||
local prompt_input = prompt_select .. " y/n: "
|
|
||||||
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
|
|
||||||
utils.clear_prompt()
|
|
||||||
if item_short == "y" then
|
|
||||||
create_and_notify(file)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
create_and_notify(file)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_num_nodes(iter)
|
local function get_num_nodes(iter)
|
||||||
local i = 0
|
local i = 0
|
||||||
for _ in iter do
|
for _ in iter do
|
||||||
@ -91,7 +76,7 @@ function M.fn(node)
|
|||||||
path_to_create = utils.path_join { path_to_create, p }
|
path_to_create = utils.path_join { path_to_create, p }
|
||||||
end
|
end
|
||||||
if is_last_path_file and idx == num_nodes then
|
if is_last_path_file and idx == num_nodes then
|
||||||
create_file(path_to_create)
|
create_and_notify(path_to_create)
|
||||||
elseif not utils.file_exists(path_to_create) then
|
elseif not utils.file_exists(path_to_create) then
|
||||||
local success = vim.loop.fs_mkdir(path_to_create, 493)
|
local success = vim.loop.fs_mkdir(path_to_create, 493)
|
||||||
if not success then
|
if not success then
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user