(args []string)
| 49 | } |
| 50 | |
| 51 | func (cmd *diskUsageCommand) Run(args []string) (err error) { |
| 52 | reexec() |
| 53 | |
| 54 | // Create the context. |
| 55 | id := identity.NewID() |
| 56 | ctx := session.NewContext(context.Background(), id) |
| 57 | ctx = namespaces.WithNamespace(ctx, "buildkit") |
| 58 | |
| 59 | // Create the client. |
| 60 | c, err := client.New(stateDir, backend, nil) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | defer c.Close() |
| 65 | |
| 66 | resp, err := c.DiskUsage(ctx, &controlapi.DiskUsageRequest{Filter: cmd.filters.GetAll()}) |
| 67 | if err != nil { |
| 68 | return err |
| 69 | } |
| 70 | |
| 71 | tw := tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0) |
| 72 | |
| 73 | if debug { |
| 74 | printDebug(tw, resp.Record) |
| 75 | } else { |
| 76 | fmt.Fprintln(tw, "ID\tRECLAIMABLE\tSIZE\tDESCRIPTION") |
| 77 | |
| 78 | for _, di := range resp.Record { |
| 79 | id := di.ID |
| 80 | if di.Mutable { |
| 81 | id += "*" |
| 82 | } |
| 83 | desc := di.Description |
| 84 | if len(desc) > 50 { |
| 85 | desc = desc[0:50] + "..." |
| 86 | } |
| 87 | fmt.Fprintf(tw, "%s\t%t\t%s\t%s\n", id, !di.InUse, units.BytesSize(float64(di.Size_)), desc) |
| 88 | } |
| 89 | |
| 90 | tw.Flush() |
| 91 | } |
| 92 | |
| 93 | if cmd.filters.Len() < 1 { |
| 94 | total := int64(0) |
| 95 | reclaimable := int64(0) |
| 96 | |
| 97 | for _, di := range resp.Record { |
| 98 | if di.Size_ > 0 { |
| 99 | total += di.Size_ |
| 100 | if !di.InUse { |
| 101 | reclaimable += di.Size_ |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0) |
| 107 | fmt.Fprintf(tw, "Reclaimable:\t%s\n", units.BytesSize(float64(reclaimable))) |
| 108 | fmt.Fprintf(tw, "Total:\t%s\n", units.BytesSize(float64(total))) |
no test coverage detected