Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.
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
57 changes: 39 additions & 18 deletions src/WinRPM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,54 @@ 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}(undef, 261)
for i in 1:retry
res = ccall((:URLDownloadToCacheFileW, :urlmon), stdcall, Cuint,
(Ptr{Cvoid}, Ptr{UInt16}, Ptr{UInt16}, Clong, Cint, Ptr{Cvoid}),
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")
end
return "", 0
end
else
error("Platform not supported: $(Sys.KERNEL)")
end
elseif iswindows()
else
function download(source::AbstractString; retry=5)
dest = Vector{UInt16}(undef, 261)
for i in 1:retry
res = ccall((:URLDownloadToCacheFileW, :urlmon), stdcall, Cuint,
(Ptr{Cvoid}, Ptr{UInt16}, Ptr{UInt16}, Clong, Cint, Ptr{Cvoid}),
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])
Copy link
Contributor

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

Copy link
Author

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?

Copy link
Contributor

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.

filename = Base.download(source, filename)
if isfile(filename)
return read(filename, String), 200
return readstring(filename), 200
end
catch ex
if i == retry
@warn("download from $source failed: $ex")
return "", 0
end
else
@warn("Unknown download failure, error code: $res")
end
@warn("Retry $i/$retry downloading: $source")
end
return "", 0
end
else
error("Platform not supported: $(Sys.KERNEL)")
end

getcachedir(source) = getcachedir(cachedir, source)
Expand Down Expand Up @@ -526,7 +547,7 @@ end

include("winrpm_bindeps.jl")

# deprecations
# deprecations
@deprecate help() "Please see the README.md file at https://github.com/JuliaPackaging/WinRPM.jl"

end