Skip to content

Commit 3c3d5fb

Browse files
fredrikekreKristofferC
authored andcommitted
Only run gc on the user-depot unless force=true, fixes #2642. (#2654)
(cherry picked from commit a85ac56)
1 parent 4ae524a commit 3c3d5fb

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/API.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,19 @@ marking them as "orphaned". This method will only remove orphaned objects (pack
445445
versions, artifacts, and scratch spaces) that have been continually un-used for a period
446446
of `collect_delay`; which defaults to seven days.
447447
448+
Garbage collection is only applied to the "user depot", e.g. the first entry in the
449+
depot path. If you want to run `gc` on all depots set `force=true` (this might require
450+
admin privileges depending on the setup).
451+
448452
Use verbose mode (`verbose=true`) for detailed output.
449453
"""
450-
function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false, kwargs...)
454+
function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false, force=false, kwargs...)
451455
Context!(ctx; kwargs...)
452456
env = ctx.env
453457

458+
# Only look at user-depot unless force=true
459+
gc_depots = force ? depots() : [depots1()]
460+
454461
# First, we load in our `manifest_usage.toml` files which will tell us when our
455462
# "index files" (`Manifest.toml`, `Artifacts.toml`) were last used. We will combine
456463
# this knowledge across depots, condensing it all down to a single entry per extant
@@ -467,7 +474,7 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false,
467474
scratch_parents_by_depot = Dict{String, Dict{String, Set{String}}}()
468475

469476
# Load manifest files from all depots
470-
for depot in depots()
477+
for depot in gc_depots
471478
# When a manifest/artifact.toml is installed/used, we log it within the
472479
# `manifest_usage.toml` files within `write_env_usage()` and `bind_artifact!()`
473480
function reduce_usage!(f::Function, usage_filepath)
@@ -728,7 +735,7 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false,
728735

729736
# Do an initial scan of our depots to get a preliminary `packages_to_delete`.
730737
packages_to_delete = String[]
731-
for depot in depots()
738+
for depot in gc_depots
732739
depot_orphaned_packages = String[]
733740
packagedir = abspath(depot, "packages")
734741
if isdir(packagedir)
@@ -768,7 +775,7 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false,
768775
repos_to_delete = String[]
769776
spaces_to_delete = String[]
770777

771-
for depot in depots()
778+
for depot in gc_depots
772779
# We track orphaned objects on a per-depot basis, writing out our `orphaned.toml`
773780
# tracking file immediately, only pushing onto the overall `*_to_delete` lists if
774781
# the package has been orphaned for at least a period of `collect_delay`
@@ -914,7 +921,7 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false,
914921
end
915922

916923
# Prune package paths that are now empty
917-
for depot in depots()
924+
for depot in gc_depots
918925
packagedir = abspath(depot, "packages")
919926
!isdir(packagedir) && continue
920927

@@ -928,7 +935,7 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false,
928935
end
929936

930937
# Prune scratch space UUID folders that are now empty
931-
for depot in depots()
938+
for depot in gc_depots
932939
scratch_dir = abspath(depot, "scratchspaces")
933940
!isdir(scratch_dir) && continue
934941

0 commit comments

Comments
 (0)