make.go: preserve executable bit when copying binaries to bin

Change-Id: Ia2c415aaaa2ab5ffa52766f5adfb4f5af7377961
This commit is contained in:
Brad Fitzpatrick 2013-09-21 13:23:07 +01:00
parent 43135068a5
commit b377055f1f
1 changed files with 8 additions and 0 deletions

View File

@ -497,6 +497,10 @@ func mirrorDir(src, dst string) (maxMod time.Time, err error) {
var wantDestFile = make(map[string]bool) // full dest filename => true var wantDestFile = make(map[string]bool) // full dest filename => true
func isExecMode(mode os.FileMode) bool {
return (mode & 0111) != 0
}
func mirrorFile(src, dst string) error { func mirrorFile(src, dst string) error {
wantDestFile[dst] = true wantDestFile[dst] = true
sfi, err := os.Stat(src) sfi, err := os.Stat(src)
@ -508,6 +512,7 @@ func mirrorFile(src, dst string) error {
} }
dfi, err := os.Stat(dst) dfi, err := os.Stat(dst)
if err == nil && if err == nil &&
isExecMode(sfi.Mode()) == isExecMode(dfi.Mode()) &&
(dfi.Mode()&os.ModeType == 0) && (dfi.Mode()&os.ModeType == 0) &&
dfi.Size() == sfi.Size() && dfi.Size() == sfi.Size() &&
dfi.ModTime().Unix() == sfi.ModTime().Unix() { dfi.ModTime().Unix() == sfi.ModTime().Unix() {
@ -538,6 +543,9 @@ func mirrorFile(src, dst string) error {
if err == nil { if err == nil {
err = cerr err = cerr
} }
if err == nil {
err = os.Chmod(dst, sfi.Mode())
}
if err == nil { if err == nil {
err = os.Chtimes(dst, sfi.ModTime(), sfi.ModTime()) err = os.Chtimes(dst, sfi.ModTime(), sfi.ModTime())
} }