From 9aff9301ce443a41f20d60d4c5f0d803a5a907f0 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 29 Nov 2021 16:21:35 +0100 Subject: [PATCH] disk usage: last accessed not displayed Signed-off-by: CrazyMax --- commands/diskusage.go | 23 ++++++++++++++--------- commands/prune.go | 4 ++-- go.mod | 1 - vendor/modules.txt | 1 - 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/commands/diskusage.go b/commands/diskusage.go index 223cd93b..1f1e49a4 100644 --- a/commands/diskusage.go +++ b/commands/diskusage.go @@ -5,15 +5,16 @@ import ( "io" "os" "text/tabwriter" + "time" "github.com/docker/buildx/build" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/opts" + "github.com/docker/go-units" "github.com/moby/buildkit/client" "github.com/moby/buildkit/util/appcontext" "github.com/spf13/cobra" - "github.com/tonistiigi/units" "golang.org/x/sync/errgroup" ) @@ -132,13 +133,13 @@ func printVerbose(tw *tabwriter.Writer, du []*client.UsageInfo) { printKV(tw, "Mutable", di.Mutable) printKV(tw, "Reclaimable", !di.InUse) printKV(tw, "Shared", di.Shared) - printKV(tw, "Size", fmt.Sprintf("%.2f", units.Bytes(di.Size))) + printKV(tw, "Size", units.HumanSize(float64(di.Size))) if di.Description != "" { printKV(tw, "Description", di.Description) } printKV(tw, "Usage count", di.UsageCount) if di.LastUsedAt != nil { - printKV(tw, "Last used", di.LastUsedAt) + printKV(tw, "Last used", units.HumanDuration(time.Since(*di.LastUsedAt))+" ago") } if di.RecordType != "" { printKV(tw, "Type", di.RecordType) @@ -159,11 +160,15 @@ func printTableRow(tw *tabwriter.Writer, di *client.UsageInfo) { if di.Mutable { id += "*" } - size := fmt.Sprintf("%.2f", units.Bytes(di.Size)) + size := units.HumanSize(float64(di.Size)) if di.Shared { size += "*" } - fmt.Fprintf(tw, "%-71s\t%-11v\t%s\t\n", id, !di.InUse, size) + lastAccessed := "" + if di.LastUsedAt != nil { + lastAccessed = units.HumanDuration(time.Since(*di.LastUsedAt)) + " ago" + } + fmt.Fprintf(tw, "%-40s\t%-5v\t%-10s\t%s\n", id, !di.InUse, size, lastAccessed) } func printSummary(tw *tabwriter.Writer, dus [][]*client.UsageInfo) { @@ -186,11 +191,11 @@ func printSummary(tw *tabwriter.Writer, dus [][]*client.UsageInfo) { } if shared > 0 { - fmt.Fprintf(tw, "Shared:\t%.2f\n", units.Bytes(shared)) - fmt.Fprintf(tw, "Private:\t%.2f\n", units.Bytes(total-shared)) + fmt.Fprintf(tw, "Shared:\t%s\n", units.HumanSize(float64(shared))) + fmt.Fprintf(tw, "Private:\t%s\n", units.HumanSize(float64(total-shared))) } - fmt.Fprintf(tw, "Reclaimable:\t%.2f\n", units.Bytes(reclaimable)) - fmt.Fprintf(tw, "Total:\t%.2f\n", units.Bytes(total)) + fmt.Fprintf(tw, "Reclaimable:\t%s\n", units.HumanSize(float64(reclaimable))) + fmt.Fprintf(tw, "Total:\t%s\n", units.HumanSize(float64(total))) tw.Flush() } diff --git a/commands/prune.go b/commands/prune.go index b4207ae5..237ce9ed 100644 --- a/commands/prune.go +++ b/commands/prune.go @@ -12,11 +12,11 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/opts" "github.com/docker/docker/api/types/filters" + "github.com/docker/go-units" "github.com/moby/buildkit/client" "github.com/moby/buildkit/util/appcontext" "github.com/pkg/errors" "github.com/spf13/cobra" - "github.com/tonistiigi/units" "golang.org/x/sync/errgroup" ) @@ -119,7 +119,7 @@ func runPrune(dockerCli command.Cli, opts pruneOptions) error { <-printed tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0) - fmt.Fprintf(tw, "Total:\t%.2f\n", units.Bytes(total)) + fmt.Fprintf(tw, "Total:\t%s\n", units.HumanSize(float64(total))) tw.Flush() return nil } diff --git a/go.mod b/go.mod index dd38251f..bc7d92e3 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,6 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.7.0 github.com/theupdateframework/notary v0.6.1 // indirect - github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea github.com/zclconf/go-cty v1.7.1 go.opentelemetry.io/otel v1.0.0-RC1 go.opentelemetry.io/otel/trace v1.0.0-RC1 diff --git a/vendor/modules.txt b/vendor/modules.txt index 800fa5ad..8008c482 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -422,7 +422,6 @@ github.com/tonistiigi/fsutil github.com/tonistiigi/fsutil/prefix github.com/tonistiigi/fsutil/types # github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea -## explicit github.com/tonistiigi/units # github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f github.com/tonistiigi/vt100