Last active
August 8, 2019 06:28
-
-
Save vdayanand/3db7d8e01e8a617b167570a756ba259d to your computer and use it in GitHub Desktop.
UpdateRegistry.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Pkg, LibGit2, CredentialsHandler | |
function update_registry(name) | |
tmpdir = mktempdir() | |
tmpfile = joinpath(tmpdir, "tmp.tar.gz") | |
CredentialsHandler.download("$(ENV["JULIA_PKG_SERVER"])/$(name).tar.gz", tmpfile) | |
@info "Downloaded Registry tmp at ", tmpfile | |
dest = joinpath(Pkg.depots1(), "registries") | |
@static if Sys.iswindows() | |
run(`$(joinpath(Sys.BINDIR, "7z.exe")) x -y $(tmpfile) -o$(tmpdir) -r`) | |
run(`$(joinpath(Sys.BINDIR, "7z.exe")) x -y $(tmpfile[1:end-3]) -o$(tmpdir) -r`) | |
else | |
run(`tar -xzf $tmpfile -C $(tmpdir)`) | |
end | |
@info "Extraction successfull ?", isdir(joinpath(tmpdir, name)) | |
@info "Removing dest registry if exists ", joinpath(dest,name) | |
isdir(joinpath(dest,name)) && rm(joinpath(dest,name), force = true, recursive = true) | |
@info "Copying registry to ", joinpath(dest,name) | |
cp(joinpath(tmpdir, name), joinpath(dest,name)) | |
@info "Removing temp registry at ", joinpath(tmpdir,name) | |
rm(joinpath(tmpdir,name), force = true, recursive = true) | |
@info "Setting remote..." | |
try | |
repo = LibGit2.init(normpath(joinpath(DEPOT_PATH[1],"registries",name))) | |
LibGit2.set_remote_url(repo, "origin", ENV["JULIA_PKG_SERVER"]*"/registry/$name") | |
catch ex | |
@warn "Setting remote failed", ex | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment