-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Allow download to take a local directory to download into #33088
Conversation
For reference of others reading this later: This PR is largely orthogonal to #27043 and #32804 And re: #32804 which more broadly considers options. |
I don't really like that the meaning of the second argument changes based on whether it exists and is a directory. That feels like it's just asking for bugs and confusion. Having the meaning of code depend on global mutable state in a program is generally bad; having it depend on global mutable state this is in the file system is so much worse than that. |
That is a fair-point. What do you think would be a better way to achieve this goal? To me downloading into a user provided directory is something that Getting the second part (server-provided filename)is a bit harder (but not nesc all that hard, with the right commandline flags). I guess there are other options like a |
Which is the reasonable thing to do. The meaning of the command doesn't change, all that changes is whether it can be carried out or not.
What's the reason to want this? Note that d = mktempdir()
file1 = download(url1, mktemp(d)[1])
file2 = download(url2, mktemp(d)[1]) Now all the files are in |
It does occur to me that using d = mktempdir()
file1 = download(url1, tempname(d))
file2 = download(url2, tempname(d)) |
I've made a pull request to improve |
For interest that change is in this PR also |
Changes to public functions like that should not be snuck with other changes 😐 |
Yes, indeed |
The short-answer is I was thinking in case of name collision we would do a extension preserving rename. |
Need to be moved to Downloads.jl if you are still interested in moving forward with this. |
With this PR if the user does
download(url, localdir)
wherelocaldir
is a path to a directory that currently exiists,then
download
will create a file with atempname
within that directory and download into it.This has a few minor uses. Like easier debugging if you can specify all your downloads go somewhere specific so you can manually inspect them; and the ability to clean them all up after by deleting that known directory.
In the future we might be able to provide the full functionality
HTTP.download
haswhere the filename is worked out based on the HTTP rules, and then placed into the directory, with that name.
https://github.com/JuliaWeb/HTTP.jl/blob/668e7e68747bb333ebde13af8d16add5b82b3b8a/src/download.jl#L78-L85
(There are some flags for this in curl and wget, fetch had an argument about adding this 12 years ago, idk if they did add it or not, but anyway that is a future PR)
This is non-breaking, as without this PR providing a local-path to a directory would cause an error to be thrown.