Skip to content

Commit

Permalink
cmd/go: don't ignore error when 'go clean'
Browse files Browse the repository at this point in the history
        Fixes golang#4208.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/6635064
  • Loading branch information
minux committed Oct 10, 2012
1 parent be2b95f commit bf7d229
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/cmd/go/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ func clean(p *Package) {
continue
}
}
os.RemoveAll(filepath.Join(p.Dir, name))
if err := os.RemoveAll(filepath.Join(p.Dir, name)); err != nil {
errorf("go clean: %v", err)
}
}
continue
}
Expand All @@ -180,7 +182,7 @@ func clean(p *Package) {
}

if cleanFile[name] || cleanExt[filepath.Ext(name)] || toRemove[name] {
os.Remove(filepath.Join(p.Dir, name))
removeFile(filepath.Join(p.Dir, name))
}
}

Expand All @@ -189,7 +191,7 @@ func clean(p *Package) {
b.showcmd("", "rm -f %s", p.target)
}
if !cleanN {
os.Remove(p.target)
removeFile(p.target)
}
}

Expand All @@ -202,7 +204,7 @@ func clean(p *Package) {
b.showcmd("", "rm -f %s", target)
}
if !cleanN {
os.Remove(target)
removeFile(target)
}
}
}
Expand All @@ -213,3 +215,11 @@ func clean(p *Package) {
}
}
}

// removeFile tries to remove file f, if error other than file doesn't exist
// occurs, it will report the error.
func removeFile(f string) {
if err := os.Remove(f); err != nil && !os.IsNotExist(err) {
errorf("go clean: %v", err)
}
}

0 comments on commit bf7d229

Please sign in to comment.