From bbd76e0207be8e53e97da78210db5be228cfaf6a Mon Sep 17 00:00:00 2001 From: brianhuster Date: Fri, 29 Nov 2024 01:14:41 +0700 Subject: [PATCH] update --- lua/dirvish-do/init.lua | 10 +++++++--- lua/dirvish-do/operations.lua | 13 ++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lua/dirvish-do/init.lua b/lua/dirvish-do/init.lua index 13a54cd..e0eaa29 100644 --- a/lua/dirvish-do/init.lua +++ b/lua/dirvish-do/init.lua @@ -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() diff --git a/lua/dirvish-do/operations.lua b/lua/dirvish-do/operations.lua index a1411c2..97b93d1 100644 --- a/lua/dirvish-do/operations.lua +++ b/lua/dirvish-do/operations.lua @@ -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