]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't ignore error when 'go clean'
authorShenghou Ma <minux.ma@gmail.com>
Wed, 10 Oct 2012 17:34:26 +0000 (01:34 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Wed, 10 Oct 2012 17:34:26 +0000 (01:34 +0800)
        Fixes #4208.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/6635064

src/cmd/go/clean.go

index b148eaaec886b733106281c6c22852e2787049d5..ba600d3bb1b3249e2de42c1ef84b031934c8fcae 100644 (file)
@@ -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
                }
@@ -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))
                }
        }
 
@@ -189,7 +191,7 @@ func clean(p *Package) {
                        b.showcmd("", "rm -f %s", p.target)
                }
                if !cleanN {
-                       os.Remove(p.target)
+                       removeFile(p.target)
                }
        }
 
@@ -202,7 +204,7 @@ func clean(p *Package) {
                                b.showcmd("", "rm -f %s", target)
                        }
                        if !cleanN {
-                               os.Remove(target)
+                               removeFile(target)
                        }
                }
        }
@@ -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)
+       }
+}