Skip to content

Commit 45c724f

Browse files
committed
fix: use Plenary for copying file/folders, fixes #196
1 parent fa8501e commit 45c724f

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lua/neo-tree/sources/filesystem/lib/fs_actions.lua

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ local utils = require("neo-tree.utils")
1212
local inputs = require("neo-tree.ui.inputs")
1313
local events = require("neo-tree.events")
1414
local log = require("neo-tree.log")
15+
local Path = require("plenary.path")
1516

1617
local M = {}
1718

@@ -94,21 +95,25 @@ end
9495

9596
-- Copy Node
9697
M.copy_node = function(source, _destination, callback)
97-
local parent_path, name = utils.split_path(source)
98+
local _, name = utils.split_path(source)
9899
get_unused_name(_destination or source, function(destination)
99-
create_all_parents(destination)
100-
loop.fs_copyfile(source, destination, function(err)
101-
if err then
102-
log.error("Could not copy the files from", source, "to", destination, ":", err)
103-
return
104-
end
100+
local path = Path:new(source)
101+
local success, result = pcall(path.copy, path, {
102+
destination = destination,
103+
recursive = true,
104+
parents = true,
105+
})
106+
107+
if not success then
108+
log.error("Could not copy the files from", source, "to", destination, ":", result)
109+
return
110+
end
105111
vim.schedule(function()
106112
events.fire_event(events.FILE_ADDED, destination)
107113
if callback then
108114
callback(source, destination)
109115
end
110116
end)
111-
end)
112117
end, 'Copy "' .. name .. '" to:')
113118
end
114119

0 commit comments

Comments
 (0)