Skip to content
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

Fix #9932 #11024

Merged
merged 1 commit into from
May 5, 2015
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions base/pkg/dir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ function init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRA
end
dir = path()
info("Initializing package repository $dir")
temp_dir = mktempdir()
metadata_dir = joinpath(dir, "METADATA")
if isdir(metadata_dir)
info("Package directory $dir is already initialized.")
Git.set_remote_url(meta, dir=metadata_dir)
return
end
try
mkpath(dir)
Base.cd(dir) do
mkpath(temp_dir)
Base.cd(temp_dir) do
info("Cloning METADATA from $meta")
run(`git clone -q -b $branch $meta METADATA`)
Git.set_remote_url(meta, dir="METADATA")
Expand All @@ -54,8 +55,15 @@ function init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRA
close(io)
end
end
#Move TEMP to METADATA
mkpath(dir)
Base.mv(joinpath(temp_dir,"METADATA"), metadata_dir)
Base.mv(joinpath(temp_dir,"REQUIRE"), joinpath(dir,"REQUIRE"))
Base.mv(joinpath(temp_dir,"META_BRANCH"), joinpath(dir,"META_BRANCH"))
rm(temp_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this not rm(temp_dir, recursive=true)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think it has to be since there shouldn't be anything left in it at this point, but maybe more defensive that way

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arg sorry for the noise, it is moving the directories not copying them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakebolewski If the directory is not empty it then will error.
I had it the other way initially but thought that if some other change comes around which isn't accounted for in this then it will error.

I am not too sure whether this is a good thing though. It means if somebody adds an extra item to Pkg.init() it needs to be explicitly handled whereas if I had moved temp_dir to dir instead of each item individually that wouldn't have been a problem.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better for that not to be a silent error, but it seems like this is kind of an unfortunately brittle arrangement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't be silent, would it? I'd think make test-pkg would show the error pretty quickly. If dir already happens to exist then I don't think it would work to move temp_dir to dir. I don't think we have a force kwarg for mv.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the current behavior is better since it would fail if this directory weren't empty, so I guess we're ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without using -force which isn't available there is the option of removing the specific version directory completely though that also seems like it could have unintended consequences as well.

catch e
ispath(metadata_dir) && rm(metadata_dir, recursive=true)
ispath(temp_dir) && rm(temp_dir, recursive=true)
rethrow(e)
end
end
Expand Down
5 changes: 4 additions & 1 deletion test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ function temp_pkg_dir(fn::Function)
end
end

# Test adding a removing a package
# Test adding or removing a package
#Also test for the existence of REUIRE and META_Branch
temp_pkg_dir() do
@test isfile(joinpath(Pkg.dir(),"REQUIRE"))
@test isfile(joinpath(Pkg.dir(),"META_BRANCH"))
@test isempty(Pkg.installed())
Pkg.add("Example")
@test [keys(Pkg.installed())...] == ["Example"]
Expand Down