From b377055f1fdc34f74373965d3ac1676306b4b150 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 21 Sep 2013 13:23:07 +0100 Subject: [PATCH] make.go: preserve executable bit when copying binaries to bin Change-Id: Ia2c415aaaa2ab5ffa52766f5adfb4f5af7377961 --- make.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/make.go b/make.go index 8f4813f6d..df6fdacf9 100644 --- a/make.go +++ b/make.go @@ -497,6 +497,10 @@ func mirrorDir(src, dst string) (maxMod time.Time, err error) { 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 { wantDestFile[dst] = true sfi, err := os.Stat(src) @@ -508,6 +512,7 @@ func mirrorFile(src, dst string) error { } dfi, err := os.Stat(dst) if err == nil && + isExecMode(sfi.Mode()) == isExecMode(dfi.Mode()) && (dfi.Mode()&os.ModeType == 0) && dfi.Size() == sfi.Size() && dfi.ModTime().Unix() == sfi.ModTime().Unix() { @@ -538,6 +543,9 @@ func mirrorFile(src, dst string) error { if err == nil { err = cerr } + if err == nil { + err = os.Chmod(dst, sfi.Mode()) + } if err == nil { err = os.Chtimes(dst, sfi.ModTime(), sfi.ModTime()) }