Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: copy file to non-existing folder #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lua/plenary/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ function Path:copy(opts)
opts = opts or {}
opts.recursive = F.if_nil(opts.recursive, false, opts.recursive)
opts.override = F.if_nil(opts.override, true, opts.override)
opts.parents = F.if_nil(opts.parents, false, opts.parents)
opts.exists_ok = F.if_nil(opts.exists_ok, true, opts.exists_ok)

local dest = opts.destination
-- handles `.`, `..`, `./`, and `../`
Expand All @@ -541,6 +543,12 @@ function Path:copy(opts)
end
)
else
if opts.parents then
local parent = dest:parent()
if not parent:exists() then
parent:mkdir { parents = opts.parents, exists_ok = opts.exists_ok }
end
end
-- nil: not overriden if `override = false`
success[dest] = uv.fs_copyfile(self:absolute(), dest:absolute(), { excl = not opts.override }) or false
end
Expand All @@ -549,8 +557,8 @@ function Path:copy(opts)
-- dir
if opts.recursive then
dest:mkdir {
parents = F.if_nil(opts.parents, false, opts.parents),
exists_ok = F.if_nil(opts.exists_ok, true, opts.exists_ok),
parents = opts.parents,
exists_ok = opts.exists_ok,
}
local scan = require "plenary.scandir"
local data = scan.scan_dir(self.filename, {
Expand Down