-
Notifications
You must be signed in to change notification settings - Fork 44
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
Use powershell command for download #144
base: master
Are you sure you want to change the base?
Changes from 8 commits
3bda801
b830d32
4c5d007
3860451
c2fe28c
fccd061
f19c019
9b5860c
6de4f21
c5a7269
490894e
5d71829
4d7a98c
aa460e8
313815c
8e13c39
de0bebb
521e0e1
e8bac66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
julia 0.6 | ||
Compat 0.42.0 | ||
Compat 0.56.0 | ||
URIParser 0.0.3 | ||
@unix HTTPClient 0.0.0 | ||
LibExpat 0.2.8 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,33 +46,55 @@ function __init__() | |
update(false, false) | ||
end | ||
|
||
if isunix() | ||
function download(source::AbstractString) | ||
x = HTTPC.get(source) | ||
unsafe_string(x.body), x.http_code | ||
if VERSION < v"0.7.0-DEV" | ||
if isunix() | ||
function download(source::AbstractString) | ||
x = HTTPC.get(source) | ||
unsafe_string(x.body), x.http_code | ||
end | ||
elseif iswindows() | ||
function download(source::AbstractString; retry=5) | ||
dest = Vector{UInt16}(261) | ||
for i in 1:retry | ||
res = ccall((:URLDownloadToCacheFileW, :urlmon), stdcall, Cuint, | ||
(Ptr{Void}, Ptr{UInt16}, Ptr{UInt16}, Clong, Cint, Ptr{Void}), | ||
C_NULL, transcode(UInt16, source), dest, sizeof(dest) >> 1, 0, C_NULL) | ||
if res == 0 | ||
resize!(dest, findfirst(iszero, dest) - 1) | ||
filename = transcode(String, dest) | ||
if isfile(filename) | ||
return read(filename, String), 200 | ||
end | ||
else | ||
warn("Unknown download failure, error code: $res") | ||
end | ||
warn("Retry $i/$retry downloading: $source") | ||
return "", 0 | ||
end | ||
end | ||
else | ||
error("Platform not supported: $(Sys.KERNEL)") | ||
end | ||
elseif iswindows() | ||
else | ||
function download(source::AbstractString; retry=5) | ||
dest = Vector{UInt16}(261) | ||
for i in 1:retry | ||
res = ccall((:URLDownloadToCacheFileW, :urlmon), stdcall, Cuint, | ||
(Ptr{Void}, Ptr{UInt16}, Ptr{UInt16}, Clong, Cint, Ptr{Void}), | ||
C_NULL, transcode(UInt16, source), dest, sizeof(dest) >> 1, 0, C_NULL) | ||
if res == 0 | ||
resize!(dest, findfirst(iszero, dest) - 1) | ||
filename = transcode(String, dest) | ||
try | ||
filename = joinpath(tempdir(), split(source, "/")[end]) | ||
filename = Base.download(source, filename) | ||
if isfile(filename) | ||
return read(filename, String), 200 | ||
return readstring(filename), 200 | ||
end | ||
else | ||
warn("Unknown download failure, error code: $res") | ||
catch ex | ||
warn("Unknown download failure. Retry $i/$retry downloading: $source") | ||
end | ||
warn("Retry $i/$retry downloading: $source") | ||
end | ||
warn("""Unknown download failure in `Base.download` function""") | ||
if iswindows() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just rethrow the exception raised by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't rethrow the error. This is not what the rest of WinRPM code expect - it expects to print the error as a warning and send a errcode !=200. The
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Just printing the message should be OK. |
||
warn("Base.download function relies on Windows PowerShell functionality. "* | ||
"Check that PowerShell 3 or higher is installed and TLS 1.2 protocol support enabled.") | ||
end | ||
return "", 0 | ||
end | ||
else | ||
error("Platform not supported: $(Sys.KERNEL)") | ||
end | ||
|
||
getcachedir(source) = getcachedir(cachedir, source) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks highly likely to have collisions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you'd rather not enforce the filename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, don't drop most of source.