MCPcopy
hub / github.com/genuinetools/img / Run

Method Run

prune.go:40–100  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

38type pruneCommand struct{}
39
40func (cmd *pruneCommand) Run(args []string) (err error) {
41 reexec()
42
43 // Create the context.
44 id := identity.NewID()
45 ctx := session.NewContext(context.Background(), id)
46 ctx = namespaces.WithNamespace(ctx, "buildkit")
47
48 // Create the client.
49 c, err := client.New(stateDir, backend, nil)
50 if err != nil {
51 return err
52 }
53 defer c.Close()
54
55 usage, err := c.Prune(ctx)
56 if err != nil {
57 return err
58 }
59
60 tw := tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0)
61
62 if debug {
63 printDebug(tw, usage)
64 } else {
65 fmt.Fprintln(tw, "ID\tRECLAIMABLE\tSIZE\tDESCRIPTION")
66
67 for _, di := range usage {
68 id := di.ID
69 if di.Mutable {
70 id += "*"
71 }
72 desc := di.Description
73 if len(desc) > 50 {
74 desc = desc[0:50] + "..."
75 }
76 fmt.Fprintf(tw, "%s\t%t\t%s\t%s\n", id, !di.InUse, units.BytesSize(float64(di.Size_)), desc)
77 }
78
79 tw.Flush()
80 }
81
82 total := int64(0)
83 reclaimable := int64(0)
84
85 for _, di := range usage {
86 if di.Size_ > 0 {
87 total += di.Size_
88 if !di.InUse {
89 reclaimable += di.Size_
90 }
91 }
92 }
93
94 tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0)
95 fmt.Fprintf(tw, "Reclaimed:\t%s\n", units.BytesSize(float64(reclaimable)))
96 fmt.Fprintf(tw, "Total:\t%s\n", units.BytesSize(float64(total)))
97 tw.Flush()

Callers 1

newPruneCommandFunction · 0.95

Calls 5

NewFunction · 0.92
reexecFunction · 0.85
printDebugFunction · 0.85
CloseMethod · 0.80
PruneMethod · 0.80

Tested by

no test coverage detected