Skip to content

Commit

Permalink
Change collect_delay to be a Dates.Period
Browse files Browse the repository at this point in the history
This gives greater clarity on the meaning behind `collect_delay`.
  • Loading branch information
staticfloat committed Aug 15, 2019
1 parent 8197e22 commit 3d5bec2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
9 changes: 3 additions & 6 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,19 @@ function __installed(mode::PackageMode=PKGMODE_MANIFEST)
end

"""
gc(ctx::Context=Context(); kwargs...)
gc(ctx::Context=Context(); collect_delay::Period=Day(30), kwargs...)
Garbage-collect package and artifact installations by sweeping over all known
`Manifest.toml` and `Artifacts.toml` files, noting those that have been deleted, and then
finding artifacts and packages that are thereafter not used by any other projects. This
method will only remove package versions and artifacts that have been continually un-used
for a period of `collect_delay`; which defaults to thirty days.
"""
function gc(ctx::Context=Context(); collect_delay=60*60*24*30, kwargs...)
function gc(ctx::Context=Context(); collect_delay::Period=Day(30), kwargs...)
Context!(ctx; kwargs...)
ctx.preview && preview_info()
env = ctx.env

# Convert to a DateTime immediately, offering millisecond resolution
collect_delay = Millisecond(round(Int64,1000*collect_delay))

# First, we load in our `manifest_usage.toml` files which will tell us when our
# "index files" (`Manifest.toml`, `Artifacts.toml`) were last used. We will combine
# this knowledge across depots, condensing it all down to a single entry per extant
Expand Down Expand Up @@ -494,7 +491,7 @@ function gc(ctx::Context=Context(); collect_delay=60*60*24*30, kwargs...)
for depot in depots()
# We track orphaned objects on a per-depot basis, writing out our `orphaned.toml`
# tracking file immediately, only pushing onto the overall `*_to_delete` lists if
# the package has been orphaned for at least `collect_delay` seconds.
# the package has been orphaned for at least a period of `collect_delay`
depot_orphaned_packages = String[]
depot_orphaned_artifacts = String[]

Expand Down
6 changes: 3 additions & 3 deletions test/artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ArtifactTests

using Test, Pkg.Artifacts, Pkg.BinaryPlatforms, Pkg.PlatformEngines
import Pkg.Artifacts: pack_platform!, unpack_platform, with_artifacts_directory
using Pkg.TOML
using Pkg.TOML, Dates
import Base: SHA1

include("utils.jl")
Expand Down Expand Up @@ -359,7 +359,7 @@ end
# This should reap the `die_hash` immediately, as it has already been moved to
# the orphaned list.
sleep(0.2)
Pkg.gc(;collect_delay=0.1)
Pkg.gc(;collect_delay=Millisecond(100))
@test artifact_exists(live_hash)
@test !artifact_exists(die_hash)

Expand All @@ -374,7 +374,7 @@ end
# Next, unbind the live_hash, then run with collect_delay=0, and ensure that
# things are cleaned up immediately.
unbind_artifact!(artifacts_toml, "live")
Pkg.gc(;collect_delay=0)
Pkg.gc(;collect_delay=Second(0))
@test !artifact_exists(live_hash)
@test !artifact_exists(die_hash)
end
Expand Down
5 changes: 3 additions & 2 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Random: randstring
import LibGit2
using Test
using UUIDs
using Dates

using Pkg
using Pkg.Types
Expand Down Expand Up @@ -135,11 +136,11 @@ temp_pkg_dir() do project_path
pkgdir = joinpath(Pkg.depots1(), "packages")

# Test to ensure that with a long enough collect_delay, nothing gets reaped
Pkg.gc(;collect_delay=1000)
Pkg.gc(;collect_delay=Day(1000))
@test !isempty(readdir(pkgdir))

# Setting collect_delay to zero causes it to be reaped immediately, howeveage
Pkg.gc(;collect_delay=0)
Pkg.gc(;collect_delay=Second(0))
@test isempty(readdir(pkgdir))
end

Expand Down

0 comments on commit 3d5bec2

Please sign in to comment.