]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: always copy files on Windows
authorIan Lance Taylor <iant@golang.org>
Tue, 24 Oct 2017 14:22:26 +0000 (07:22 -0700)
committerIan Lance Taylor <iant@golang.org>
Sat, 18 Nov 2017 06:31:57 +0000 (06:31 +0000)
Copying ensures that we respect the NTFS permissions of the parent folder.
I don't know if there is a way to tell when it is safe to simply rename.

Fixes #22343

Change-Id: I424bfe655b53b0e0fe425ce92bbc15450d52d851
Reviewed-on: https://go-review.googlesource.com/72910
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/cmd/go/internal/work/exec.go

index 405abc4323c4d4744ac0abffb26f37359258e1d7..c17e5295515848a3a5fef5a5351e54ab07a95d33 100644 (file)
@@ -18,6 +18,7 @@ import (
        "os/exec"
        "path/filepath"
        "regexp"
+       "runtime"
        "strconv"
        "strings"
        "sync"
@@ -1065,6 +1066,14 @@ func (b *Builder) moveOrCopyFile(a *Action, dst, src string, perm os.FileMode, f
                return b.copyFile(a, dst, src, perm, force)
        }
 
+       // On Windows, always copy the file, so that we respect the NTFS
+       // permissions of the parent folder. https://golang.org/issue/22343.
+       // What matters here is not cfg.Goos (the system we are building
+       // for) but runtime.GOOS (the system we are building on).
+       if runtime.GOOS == "windows" {
+               return b.copyFile(a, dst, src, perm, force)
+       }
+
        // If the destination directory has the group sticky bit set,
        // we have to copy the file to retain the correct permissions.
        // https://golang.org/issue/18878