Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhuster committed Nov 28, 2024
1 parent fb71526 commit bbd76e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lua/dirvish-do/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,17 @@ M.copy = function()
local new_dir = fn.expand("%")
local newpath
for _, target in ipairs(targets) do
local isDir = target:sub(-1) == sep
if isDir then
local stat = uv.fs_lstat(target)
local type = stat and stat.type
if type == 'directory' then
newpath = fs.joinpath(new_dir, fs.basename(target:sub(1, -2)))
utils.copydir(target, newpath)
else
elseif type == 'file' then
newpath = fs.joinpath(new_dir, fs.basename(target))
utils.copyfile(target, newpath)
elseif type == 'link' then
newpath = fs.joinpath(new_dir, fs.basename(target))
utils.copylink(target, newpath)
end
end
Dirvish()
Expand Down
13 changes: 12 additions & 1 deletion lua/dirvish-do/operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,23 @@ function M.copydir(dir, newpath)
local filepath = fs.joinpath(dir, name)
if type == "directory" then
M.copydir(filepath, fs.joinpath(newpath, name))
else
elseif type == "file" then
M.copyfile(filepath, fs.joinpath(newpath, name))
elseif type == "link" then
M.copylink(filepath, fs.joinpath(newpath, name))
end
end
end

---@param oldpath string
---@param newpath string
function M.copylink(oldpath, newpath)
local target = uv.fs_readlink(oldpath)
if target then
uv.fs_symlink(target, newpath)
end
end

---@param oldPath string
---@param newPath string
---@return boolean|nil, string|nil, string|nil
Expand Down

0 comments on commit bbd76e0

Please sign in to comment.