Skip to content

Commit

Permalink
Merge #634
Browse files Browse the repository at this point in the history
634: fix gc in prescence of normal files r=KristofferC a=KristofferC

Fixes #601 

Co-authored-by: Kristoffer Carlsson <kcarlsson89@gmail.com>
  • Loading branch information
bors[bot] and KristofferC committed Aug 13, 2018
2 parents adcf355 + a3561e4 commit 83315b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,6 @@ function __installed(mode::PackageMode=PKGMODE_MANIFEST)
end

function gc(ctx::Context=Context(); kwargs...)
function recursive_dir_size(path)
size = 0
for (root, dirs, files) in walkdir(path)
for file in files
size += stat(joinpath(root, file)).size
end
end
return size
end

Context!(ctx; kwargs...)
ctx.preview && preview_info()
env = ctx.env
Expand Down Expand Up @@ -327,10 +317,12 @@ function gc(ctx::Context=Context(); kwargs...)
packagedir = abspath(depot, "packages")
if isdir(packagedir)
for name in readdir(packagedir)
for slug in readdir(joinpath(packagedir, name))
versiondir = joinpath(packagedir, name, slug)
if !(versiondir in paths_to_keep)
push!(paths_to_delete, versiondir)
if isdir(joinpath(packagedir, name))
for slug in readdir(joinpath(packagedir, name))
versiondir = joinpath(packagedir, name, slug)
if !(versiondir in paths_to_keep)
push!(paths_to_delete, versiondir)
end
end
end
end
Expand All @@ -343,6 +335,16 @@ function gc(ctx::Context=Context(); kwargs...)
end

# Delete paths for noreachable package versions and compute size saved
function recursive_dir_size(path)
size = 0
for (root, dirs, files) in walkdir(path)
for file in files
size += stat(joinpath(root, file)).size
end
end
return size
end

sz = 0
for path in paths_to_delete
sz_pkg = recursive_dir_size(path)
Expand All @@ -363,8 +365,10 @@ function gc(ctx::Context=Context(); kwargs...)
if isdir(packagedir)
for name in readdir(packagedir)
name_path = joinpath(packagedir, name)
if isempty(readdir(name_path))
!ctx.preview && Base.rm(name_path)
if isdir(name_path)
if isempty(readdir(name_path))
!ctx.preview && Base.rm(name_path)
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ temp_pkg_dir() do project_path
@test isinstalled(TEST_PKG)
Pkg.rm(TEST_PKG.name)
@test !isinstalled(TEST_PKG)
# https://github.com/JuliaLang/Pkg.jl/issues/601
pkgdir = joinpath(Pkg.depots1(), "packages")
touch(joinpath(pkgdir, ".DS_Store"))
Pkg.gc()
rm(joinpath(pkgdir, ".DS_Store"))
@test isempty(readdir(pkgdir))
end

@testset "package with wrong UUID" begin
Expand Down

0 comments on commit 83315b3

Please sign in to comment.