Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2bb7112

Browse files
committed
sweet: add -clean flag to get
This is to help clean up old copies of the assets, which use a lot of disk space. Change-Id: Id2c97f270343a0c524eea7a31db8f6e48c059945 Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/680496 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent de0a632 commit 2bb7112

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

sweet/cmd/sweet/get.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"flag"
1010
"fmt"
1111
"io"
12+
"os"
1213
"path/filepath"
1314

1415
"golang.org/x/benchmarks/sweet/cli/assets"
@@ -32,6 +33,7 @@ type getCmd struct {
3233
cache string
3334
copyDir string
3435
version string
36+
clean bool
3537
}
3638

3739
func (*getCmd) Name() string { return "get" }
@@ -44,12 +46,37 @@ func (c *getCmd) SetFlags(f *flag.FlagSet) {
4446
f.StringVar(&c.cache, "cache", assets.CacheDefault(), "cache location for assets")
4547
f.StringVar(&c.version, "version", common.Version, "the version to download assets for")
4648
f.StringVar(&c.copyDir, "copy", "", "location to extract assets into, useful for development")
49+
f.BoolVar(&c.clean, "clean", false, "delete all cached assets before installing new ones")
4750
}
4851

4952
func (c *getCmd) Run(_ []string) error {
5053
log.SetActivityLog(true)
5154
ctx := context.Background()
5255

56+
// Do some cleanup, if needed.
57+
if c.clean {
58+
for {
59+
log.Printf("Deleting cache directory %s", c.cache)
60+
fmt.Print("This is a destructive action. Please confirm. (y/n): ")
61+
var r string
62+
_, err := fmt.Scanf("%s\n", &r)
63+
if err != nil {
64+
fmt.Printf("Invalid input: %v\n", err)
65+
} else {
66+
if r == "y" {
67+
break
68+
} else if r == "n" {
69+
return nil
70+
} else {
71+
fmt.Println("Input must be exactly 'y' or 'n'.")
72+
}
73+
}
74+
}
75+
if err := os.RemoveAll(c.cache); err != nil {
76+
return fmt.Errorf("failed to delete cache directory %s: %v", c.cache, err)
77+
}
78+
}
79+
5380
// Load CIPD options, including auth, cache dir, etc. from env. The package is public, but we
5481
// want to be authenticated transparently when we pull the assets down on the builders.
5582
var opts cipd.ClientOptions

0 commit comments

Comments
 (0)