-
-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Describe the solution you'd like
Igniter.copy
to copy file(s) or directories recursively.
Describe alternatives you've considered
I currently have this in a helper module used by my tasks, but thought it may make sense for it to be supported upstream:
def igniter_copy(igniter, source, target, opts \\ [])
def igniter_copy(igniter, sources, target, opts) when is_list(sources) do
IO.puts("Batch copying #{inspect sources} to #{target}")
Enum.reduce(sources, igniter, fn source, igniter ->
igniter_copy(igniter, source, prepare_target_path(source, target), opts)
end)
end
def igniter_copy(igniter, source, target, opts) do
IO.puts("Copying #{source} to #{target}")
if File.dir?(source) do
sources = File.ls!(source)
|> Enum.map(fn file -> Path.join(source, file) end)
igniter_copy(igniter, sources, target, opts)
else
contents_to_copy = File.read!(source)
Igniter.create_or_update_file(igniter, target, contents_to_copy, fn source ->
Rewrite.Source.update(source, :content, contents_to_copy)
end)
end
end
defp prepare_target_path(source, target) do
# Remove the repeated part of source from target
if String.contains?(target, source) do
String.replace(target, source, "")
|> String.trim_leading("/")
|> (&Path.join(target, &1)).()
else
Path.join(target, Path.basename(source))
end
end
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request