MCPcopy Index your code
hub / github.com/dagger/dagger / Prune

Method Prune

cmd/dagger/shell_state.go:158–183  ·  view source on GitHub ↗

Prune removes all state instances that are not in use by a variable.

(ctx context.Context)

Source from the content-addressed store, hash-verified

156
157// Prune removes all state instances that are not in use by a variable.
158func (s *ShellStateStore) Prune(ctx context.Context) int {
159 hctx := HandlerCtx(ctx)
160 if hctx == nil {
161 return 0
162 }
163
164 used := make(map[string]struct{})
165
166 hctx.Env.Each(func(_ string, v expand.Variable) bool {
167 for key := range FindStateKeys(v.String()) {
168 used[key] = struct{}{}
169 }
170 return true
171 })
172
173 count := 0
174 s.mu.Lock()
175 for key := range s.data {
176 if _, exists := used[key]; !exists {
177 delete(s.data, key)
178 count++
179 }
180 }
181 s.mu.Unlock()
182 return count
183}
184
185func (s *ShellStateStore) debug(ctx context.Context, dump bool) {
186 slog := slog.SpanLogger(ctx, InstrumentationLibrary)

Callers

nothing calls this directly

Calls 3

HandlerCtxFunction · 0.85
FindStateKeysFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected