@@ -226,11 +226,29 @@ function download_registries(io::IO, regs::Vector{RegistrySpec}, depot::String=d
226226 else
227227 Pkg. Types. pkgerror (" no path or url specified for registry" )
228228 end
229- mv (tmp, joinpath (regdir, reg. name * " .tar.gz" ); force= true )
230- hash = pkg_server_url_hash (url)
231- reg_info = Dict (" uuid" => string (reg. uuid), " git-tree-sha1" => string (hash), " path" => reg. name * " .tar.gz" )
232- open (joinpath (regdir, reg. name * " .toml" ), " w" ) do io
233- TOML. print (io, reg_info)
229+ # verify that the clone looks like a registry
230+ if ! isfile (joinpath (tmp, " Registry.toml" ))
231+ Pkg. Types. pkgerror (" no `Registry.toml` file in cloned registry." )
232+ end
233+ registry = Registry. RegistryInstance (tmp)
234+ regpath = joinpath (regdir, registry. name)
235+ # copy to `depot`
236+ ispath (dirname (regpath)) || mkpath (dirname (regpath))
237+ if isfile (joinpath (regpath, " Registry.toml" ))
238+ existing_registry = Registry. RegistryInstance (regpath)
239+ if registry. uuid == existing_registry. uuid
240+ println (io,
241+ " Registry `$(registry. name) ` already exists in `$(Base. contractuser (regpath)) `." )
242+ else
243+ throw (Pkg. Types. PkgError (" registry `$(registry. name) =\" $(registry. uuid) \" ` conflicts with " *
244+ " existing registry `$(existing_registry. name) =\" $(existing_registry. uuid) \" `. " *
245+ " To install it you can clone it manually into e.g. " *
246+ " `$(Base. contractuser (joinpath (regdir, registry. name* " -2" ))) `." ))
247+ end
248+ elseif (url != = nothing && registry_use_pkg_server ()) || reg. linked != = true
249+ # if the dir doesn't exist, or exists but doesn't contain a Registry.toml
250+ mv (tmp, regpath, force= true )
251+ printpkgstyle (io, :Added , " registry `$(registry. name) ` to `$(Base. contractuser (regpath)) `" )
234252 end
235253 end
236254 end
@@ -337,97 +355,94 @@ function update(regs::Vector{RegistrySpec} = RegistrySpec[]; io::IO=stderr_f(),
337355 Pidfile. mkpidlock (joinpath (dirname (dirname (reg. path)), " .$(reg. name) .pid" ), stale_age = 10 ) do
338356 # only allow one julia process to update a registry at a time
339357 let regpath= regpath
340- if reg. tree_info != = nothing
341- printpkgstyle (io, :Updating , " registry at " * regpath)
342- old_hash = reg. tree_info
343- url = get (registry_urls, reg. uuid, nothing )
344- if url != = nothing
345- check_registry_state (reg)
346- end
347- if url != = nothing && (new_hash = pkg_server_url_hash (url)) != old_hash
348- # TODO : update faster by using a diff, if available
349- # TODO : DRY with the code in `download_default_registries`
350- let new_hash = new_hash, url = url
351- if registry_read_from_tarball ()
352- tmp = tempname ()
353- try
354- download_verify (url, nothing , tmp)
355- catch err
356- push! (errors, (reg. path, " failed to download from $(url) . Exception: $(sprint (showerror, err)) " ))
357- @goto done_tarball_read
358- end
359- # If we have an uncompressed Pkg server registry, remove it and get the compressed version
360- if isdir (reg. path)
361- Base. rm (reg. path; recursive= true , force= true )
362- end
363- # If we have an uncompressed Pkg server registry, remove it and get the compressed version
364- if isdir (reg. path)
365- Base. rm (reg. path; recursive= true , force= true )
366- end
367- registry_path = dirname (reg. path)
368- mv (tmp, joinpath (registry_path, reg. name * " .tar.gz" ); force= true )
369- hash = pkg_server_url_hash (url)
370- reg_info = Dict (" uuid" => string (reg. uuid), " git-tree-sha1" => string (hash), " path" => reg. name * " .tar.gz" )
371- open (joinpath (registry_path, reg. name * " .toml" ), " w" ) do io
372- TOML. print (io, reg_info)
373- end
374- @label done_tarball_read
375- else
376- mktempdir () do tmp
358+ if reg. tree_info != = nothing
359+ printpkgstyle (io, :Updating , " registry at " * regpath)
360+ old_hash = reg. tree_info
361+ url = get (registry_urls, reg. uuid, nothing )
362+ if url != = nothing
363+ check_registry_state (reg)
364+ end
365+ if url != = nothing && (new_hash = pkg_server_url_hash (url)) != old_hash
366+ # TODO : update faster by using a diff, if available
367+ # TODO : DRY with the code in `download_default_registries`
368+ let new_hash = new_hash, url = url
369+ if registry_read_from_tarball ()
370+ tmp = tempname ()
377371 try
378- download_verify_unpack (url, nothing , tmp, ignore_existence = true , io = io )
372+ download_verify (url, nothing , tmp)
379373 catch err
380- push! (errors, (reg. path, " failed to download and unpack from $(url) . Exception: $(sprint (showerror, err)) " ))
381- @goto done_tarball_unpack
374+ push! (errors, (reg. path, " failed to download from $(url) . Exception: $(sprint (showerror, err)) " ))
375+ @goto done_tarball_read
376+ end
377+ # If we have an uncompressed Pkg server registry, remove it and get the compressed version
378+ if isdir (reg. path)
379+ Base. rm (reg. path; recursive= true , force= true )
380+ end
381+ registry_path = dirname (reg. path)
382+ mv (tmp, joinpath (registry_path, reg. name * " .tar.gz" ); force= true )
383+ hash = pkg_server_url_hash (url)
384+ reg_info = Dict (" uuid" => string (reg. uuid), " git-tree-sha1" => string (hash), " path" => reg. name * " .tar.gz" )
385+ open (joinpath (registry_path, reg. name * " .toml" ), " w" ) do io
386+ TOML. print (io, reg_info)
387+ end
388+ @label done_tarball_read
389+ else
390+ mktempdir () do tmp
391+ try
392+ download_verify_unpack (url, nothing , tmp, ignore_existence = true , io= io)
393+ catch err
394+ push! (errors, (reg. path, " failed to download and unpack from $(url) . Exception: $(sprint (showerror, err)) " ))
395+ @goto done_tarball_unpack
396+ end
397+ tree_info_file = joinpath (tmp, " .tree_info.toml" )
398+ write (tree_info_file, " git-tree-sha1 = " * repr (string (new_hash)))
399+ mv (tmp, reg. path, force= true )
400+ @label done_tarball_unpack
382401 end
383- tree_info_file = joinpath (tmp, " .tree_info.toml" )
384- write (tree_info_file, " git-tree-sha1 = " * repr (string (new_hash)))
385- mv (tmp, reg. path, force= true )
386- @label done_tarball_unpack
387402 end
388403 end
389404 end
390- end
391- elseif isdir (joinpath (reg. path, " .git" ))
392- printpkgstyle (io, :Updating , " registry at " * regpath)
393- LibGit2. with (LibGit2. GitRepo (reg. path)) do repo
394- if LibGit2. isdirty (repo)
395- push! (errors, (regpath, " registry dirty" ))
396- @goto done_git
397- end
398- if ! LibGit2. isattached (repo)
399- push! (errors, (regpath, " registry detached" ))
400- @goto done_git
401- end
402- if ! (" origin" in LibGit2. remotes (repo))
403- push! (errors, (regpath, " origin not in the list of remotes" ))
404- @goto done_git
405- end
406- branch = LibGit2. headname (repo)
407- try
408- GitTools. fetch (io, repo; refspecs= [" +refs/heads/$branch :refs/remotes/origin/$branch " ])
409- catch e
410- e isa Pkg. Types. PkgError || rethrow ()
411- push! (errors, (reg. path, " failed to fetch from repo: $(e. msg) " ))
412- @goto done_git
413- end
414- ff_succeeded = try
415- LibGit2. merge! (repo; branch= " refs/remotes/origin/$branch " , fastforward= true )
416- catch e
417- e isa LibGit2. GitError && e. code == LibGit2. Error. ENOTFOUND || rethrow ()
418- push! (errors, (reg. path, " branch origin/$branch not found" ))
419- @goto done_git
420- end
421-
422- if ! ff_succeeded
423- try LibGit2. rebase! (repo, " origin/$branch " )
405+ elseif isdir (joinpath (reg. path, " .git" ))
406+ printpkgstyle (io, :Updating , " registry at " * regpath)
407+ LibGit2. with (LibGit2. GitRepo (reg. path)) do repo
408+ if LibGit2. isdirty (repo)
409+ push! (errors, (regpath, " registry dirty" ))
410+ @goto done_git
411+ end
412+ if ! LibGit2. isattached (repo)
413+ push! (errors, (regpath, " registry detached" ))
414+ @goto done_git
415+ end
416+ if ! (" origin" in LibGit2. remotes (repo))
417+ push! (errors, (regpath, " origin not in the list of remotes" ))
418+ @goto done_git
419+ end
420+ branch = LibGit2. headname (repo)
421+ try
422+ GitTools. fetch (io, repo; refspecs= [" +refs/heads/$branch :refs/remotes/origin/$branch " ])
423+ catch e
424+ e isa Pkg. Types. PkgError || rethrow ()
425+ push! (errors, (reg. path, " failed to fetch from repo: $(e. msg) " ))
426+ @goto done_git
427+ end
428+ ff_succeeded = try
429+ LibGit2. merge! (repo; branch= " refs/remotes/origin/$branch " , fastforward= true )
424430 catch e
425- e isa LibGit2. GitError || rethrow ()
426- push! (errors, (reg. path, " registry failed to rebase on origin/$branch " ))
431+ e isa LibGit2. GitError && e . code == LibGit2 . Error . ENOTFOUND || rethrow ()
432+ push! (errors, (reg. path, " branch origin/$branch not found " ))
427433 @goto done_git
428434 end
435+
436+ if ! ff_succeeded
437+ try LibGit2. rebase! (repo, " origin/$branch " )
438+ catch e
439+ e isa LibGit2. GitError || rethrow ()
440+ push! (errors, (reg. path, " registry failed to rebase on origin/$branch " ))
441+ @goto done_git
442+ end
443+ end
444+ @label done_git
429445 end
430- @label done_git
431446 end
432447 end
433448 end
0 commit comments