4

I need to get a file by URL and store it on the local disk.

I see that Mix.Utils has:

copy_path!(source, target, opts \\ [])

Which seems to do exactly what I want, but is Mix.Utils only something you'd use for writing mix tasks and not for general problem solving?

I GIVE TERRIBLE ADVICE
  • 9,578
  • 2
  • 32
  • 40
TheStoneFox
  • 3,007
  • 3
  • 31
  • 47

1 Answers1

4

Which seems to do exactly what I want, but is Mix.Utils only something you'd use for writing mix tasks and not for general problem solving?

Typically yes. If you want to use it though, you need to depend on the :mix application in your mix.exs file inside the def application function.

José Valim
  • 50,409
  • 12
  • 130
  • 115
  • 1
    Do you know of any other way of achieving what I want to do without using Mix.Utils? – TheStoneFox May 06 '15 at 10:21
  • 1
    No, you would have to write it yourself. It is short actually if you use a proper http client. The code in Mix has to deal with other complexities. – José Valim May 06 '15 at 13:21
  • The other way you could do it would be to shell out and use curl or wgets to get the file for you. But that could be done in any language; nothing specific to Elixir there. – Onorio Catenacci May 06 '15 at 13:32
  • @OnorioCatenacci that was my fall back to just use cURL :) seems a bit dirty though.. Is executing system commands viewed as bad in the erlang/elixir world? – TheStoneFox May 06 '15 at 13:51
  • I may take a look at the code in the Mix.Utils function and see if I can lift it out and utilise what I need – TheStoneFox May 06 '15 at 13:52
  • 1
    "Bad"? I am a software engineer; I don't deal in bad and good :) I just deal in more or less appropriate. If shelling out to a prebuilt command works for you, why reinvent working code? On the other hand, shelling out to a prebuilt command leaves you at the mercy of the tool maintainer and the system admin etc. etc. – Onorio Catenacci May 06 '15 at 14:02