}
// copy copies the file src to dst, via memory (so only good for small files).
-func copyfile(dst, src string, exec int) {
+func copyfile(dst, src string, flag int) {
if vflag > 1 {
errprintf("cp %s %s\n", src, dst)
}
- writefile(readfile(src), dst, exec)
+ writefile(readfile(src), dst, flag)
}
// dopack copies the package src to dst,
"const stackGuardMultiplier = %d\n"+
"var buildVersion = theVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier())
- writefile(out, file, 0)
+ writefile(out, file, writeSkipSame)
}
// mkzbootstrap writes cmd/internal/obj/zbootstrap.go:
"const goexperiment = `%s`\n",
goroot_final, go386, goarm, goextlinkenabled, findgoversion(), stackGuardMultiplier(), os.Getenv("GOEXPERIMENT"))
- writefile(out, file, 0)
+ writefile(out, file, writeSkipSame)
}
// stackGuardMultiplier returns a multiplier to apply to the default
// Copy binaries into tool binary directory.
for _, name := range bootstrapDirs {
if !strings.Contains(name, "/") {
- copyfile(pathf("%s/%s%s", tooldir, name, exe), pathf("%s/bin/%s%s", workspace, name, exe), 1)
+ copyfile(pathf("%s/%s%s", tooldir, name, exe), pathf("%s/bin/%s%s", workspace, name, exe), writeExec)
}
}
package main
import (
+ "bytes"
"fmt"
"io/ioutil"
"os"
return string(data)
}
-// writefile writes b to the named file, creating it if needed. if
-// exec is non-zero, marks the file as executable.
-func writefile(b, file string, exec int) {
+const (
+ writeExec = 1 << iota
+ writeSkipSame
+)
+
+// writefile writes b to the named file, creating it if needed.
+// if exec is non-zero, marks the file as executable.
+// If the file already exists and has the expected content,
+// it is not rewritten, to avoid changing the time stamp.
+func writefile(b, file string, flag int) {
+ new := []byte(b)
+ if flag&writeSkipSame != 0 {
+ old, err := ioutil.ReadFile(file)
+ if err == nil && bytes.Equal(old, new) {
+ return
+ }
+ }
mode := os.FileMode(0666)
- if exec != 0 {
+ if flag&writeExec != 0 {
mode = 0777
}
- err := ioutil.WriteFile(file, []byte(b), mode)
+ err := ioutil.WriteFile(file, new, mode)
if err != nil {
fatal("%v", err)
}