]> Cypherpunks repositories - gostls13.git/commitdiff
misc/makerelease: use built in "del" to remove files
authorAndrew Gerrand <adg@golang.org>
Thu, 15 Jan 2015 22:11:17 +0000 (09:11 +1100)
committerAndrew Gerrand <adg@golang.org>
Thu, 15 Jan 2015 22:24:06 +0000 (22:24 +0000)
Git marks some of its files read only, so os.RemoveAll isn't sufficient
to remove them from the ".git" directory.

Change-Id: I3150596931d1c77e7cf9fb8da1a999d2c6730121
Reviewed-on: https://go-review.googlesource.com/2930
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
misc/makerelease/makerelease.go

index f1b643cca9acfd91b10a50205971258e84f250de..b49b941f1c427809e31e226970982cc68ea9e01a 100644 (file)
@@ -775,7 +775,19 @@ func setupOAuthClient() error {
 
 func (b *Build) clean(files []string) error {
        for _, name := range files {
-               err := os.RemoveAll(filepath.Join(b.root, name))
+               path := filepath.Join(b.root, name)
+               var err error
+               if b.OS == "windows" {
+                       // Git sets some of its packfiles as 'read only',
+                       // so os.RemoveAll will fail for the ".git" directory.
+                       // Instead, shell out to cmd's 'del' subcommand.
+                       cmd := exec.Command("cmd.exe", "/C", "del", "/Q", "/F", "/S", path)
+                       cmd.Stdout = os.Stdout
+                       cmd.Stderr = os.Stderr
+                       err = cmd.Run()
+               } else {
+                       err = os.RemoveAll(path)
+               }
                if err != nil {
                        return err
                }