clean: clean mod cache should respect "-n" option.

Clean mod cache should print remove commands and not run them when with set "-n" option.
Fixes #27458.
This commit is contained in:
Tardis Xu 2018-09-03 23:59:17 +08:00
parent 5188c87c95
commit d4ba617911
1 changed files with 10 additions and 4 deletions

View File

@ -112,9 +112,10 @@ func runClean(cmd *base.Command, args []string) {
}
}
var b work.Builder
b.Print = fmt.Print
if cleanCache {
var b work.Builder
b.Print = fmt.Print
dir := cache.DefaultDir()
if dir != "off" {
// Remove the cache subdirectories but not the top cache directory.
@ -156,8 +157,13 @@ func runClean(cmd *base.Command, args []string) {
if modfetch.PkgMod == "" {
base.Fatalf("go clean -modcache: no module cache")
}
if err := removeAll(modfetch.PkgMod); err != nil {
base.Errorf("go clean -modcache: %v", err)
if cfg.BuildN || cfg.BuildX {
b.Showcmd("", "rm -r %s", modfetch.PkgMod)
}
if !cfg.BuildN {
if err := removeAll(modfetch.PkgMod); err != nil {
base.Errorf("go clean -modcache: %v", err)
}
}
}
}