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 Pkg.free() so that it never removes the specified package #24048

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ function free(pkg::AbstractString)
for ver in vers
sha1 = avail[ver].sha1
LibGit2.iscommit(sha1, repo) || continue
return LibGit2.transact(repo) do r
LibGit2.transact(repo) do r
LibGit2.isdirty(repo) && throw(PkgError("$pkg is dirty, bailing"))
LibGit2.checkout!(repo, sha1)
resolve()
end
return resolve()
Copy link
Contributor

Choose a reason for hiding this comment

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

this version isn't right either, as if the checkout fails you should restore the previous state, and not run resolve. likewise if resolve fails after checkout, should roll back.

Copy link
Member Author

Choose a reason for hiding this comment

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

I should have added a disclaimer that I blindly tried to fix the bug without being familiar with that code at all, so I wouldn't be surprised if that's totally incorrect. I can just note that the tests didn't cover that apparently, and that AFAICT the existing free(pkgs) method seems to work the same (but maybe I'm missing something). Anyway this commit doesn't need to be kept as removing the whole method also works.

end
isempty(Cache.prefetch(pkg, Read.url(pkg), [a.sha1 for (v,a)=avail])) && continue
throw(PkgError("can't find any registered versions of $pkg to checkout"))
Expand Down
14 changes: 14 additions & 0 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,17 @@ temp_pkg_dir(initialize=false) do
"INFO: Building Normal") Pkg.Entry.build!(["Exit", "Normal", "Exit", "Normal"], errors)
end
end

@testset "issue #17994" begin
temp_pkg_dir() do
@test Pkg.installed("Example.jl") === nothing
Pkg.add("Example.jl")
@test [keys(Pkg.installed())...] == ["Example"]
Pkg.checkout("Example.jl")
Pkg.rm("Example.jl")
Pkg.free("Example.jl")
iob = IOBuffer()
Pkg.status("Example.jl", iob)
@test String(take!(iob)) == "No packages installed\n"
end
end