Report each anonymous volume's size and the space freed (issue 1796)
mesh/merge-gate head 07b3c5e77a19 merged into trunk f3100d111633 — pass: builds docker → ace, g14, novox, shanks; no bus step; every machine composes with …
mesh/repo-check head 07b3c5e77a19 merged into trunk f3100d111633 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
mesh/merge-gate head 07b3c5e77a19 merged into trunk f3100d111633 — pass: builds docker → ace, g14, novox, shanks; no bus step; every machine composes with …
mesh/repo-check head 07b3c5e77a19 merged into trunk f3100d111633 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
This commit is contained in:
@@ -1232,10 +1232,11 @@ func (c *Client) RemoveAnonymousVolumes(ctx context.Context, a RemoveVolumesAsk)
|
||||
if !a.DryRun && strings.TrimSpace(a.Why) == "" {
|
||||
return nil, fmt.Errorf("why is required when dry_run is false")
|
||||
}
|
||||
all, err := c.Volumes(ctx, false, false)
|
||||
all, err := c.Volumes(ctx, false, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sizes := map[string]string{}
|
||||
candidates := []string{}
|
||||
skipped := []map[string]any{}
|
||||
skip := func(name, why string) { skipped = append(skipped, map[string]any{"name": name, "why": why}) }
|
||||
@@ -1252,12 +1253,20 @@ func (c *Client) RemoveAnonymousVolumes(ctx context.Context, a RemoveVolumesAsk)
|
||||
skip(name, "not created before "+a.CreatedBefore.Format(time.RFC3339)+" (created "+fmt.Sprint(v["created"])+")")
|
||||
default:
|
||||
candidates = append(candidates, name)
|
||||
sizes[name] = fmt.Sprint(v["size"])
|
||||
}
|
||||
}
|
||||
answer := map[string]any{"dry_run": a.DryRun, "skipped": skipped,
|
||||
"space_freed": "not reported: docker volume rm names what it removed; docker_disk_usage shows the space"}
|
||||
sum := func(names []string) int64 {
|
||||
var t int64
|
||||
for _, n := range names {
|
||||
t += max(Bytes(sizes[n]), 0)
|
||||
}
|
||||
return t
|
||||
}
|
||||
answer := map[string]any{"dry_run": a.DryRun, "skipped": skipped, "sizes": sizes}
|
||||
if a.DryRun {
|
||||
answer["would_remove"] = candidates
|
||||
answer["would_free_bytes"] = sum(candidates)
|
||||
answer["note"] = "nothing was removed: call again with dry_run false and why to remove them"
|
||||
return answer, nil
|
||||
}
|
||||
@@ -1271,6 +1280,7 @@ func (c *Client) RemoveAnonymousVolumes(ctx context.Context, a RemoveVolumesAsk)
|
||||
}
|
||||
answer["skipped"] = skipped
|
||||
answer["removed"], answer["count"], answer["why"] = removed, len(removed), a.Why
|
||||
answer["freed_bytes"] = sum(removed)
|
||||
return answer, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user