From c28324a366466569b3dc26fc89faa187e5e60c75 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Sun, 27 Mar 2022 08:49:35 -0400 Subject: [PATCH] Make auto-generated files read-only --- github/gen-accessors.go | 14 +++++++++++++- github/gen-stringify-test.go | 16 +++++++++++++++- github/github-accessors.go | 2 ++ github/github-accessors_test.go | 2 ++ github/github-stringify_test.go | 2 ++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/github/gen-accessors.go b/github/gen-accessors.go index 58ac3eb162..d8136d2c5c 100644 --- a/github/gen-accessors.go +++ b/github/gen-accessors.go @@ -186,10 +186,18 @@ func (t *templateData) dump() error { } logf("Writing %v...", filename) - if err := ioutil.WriteFile(filename, clean, 0644); err != nil { + if err := os.Chmod(filename, 0644); err != nil { + return fmt.Errorf("os.Chmod(%q, 0644): %v", filename, err) + } + + if err := ioutil.WriteFile(filename, clean, 0444); err != nil { return err } + if err := os.Chmod(filename, 0444); err != nil { + return fmt.Errorf("os.Chmod(%q, 0444): %v", filename, err) + } + return nil } @@ -329,6 +337,8 @@ const source = `// Copyright {{.Year}} The go-github AUTHORS. All rights reserve // license that can be found in the LICENSE file. // Code generated by gen-accessors; DO NOT EDIT. +// Instead, please run "go generate ./..." as described here: +// https://github.com/google/go-github/blob/master/CONTRIBUTING.md#submitting-a-patch package {{.Package}} {{with .Imports}} @@ -373,6 +383,8 @@ const test = `// Copyright {{.Year}} The go-github AUTHORS. All rights reserved. // license that can be found in the LICENSE file. // Code generated by gen-accessors; DO NOT EDIT. +// Instead, please run "go generate ./..." as described here: +// https://github.com/google/go-github/blob/master/CONTRIBUTING.md#submitting-a-patch package {{.Package}} {{with .Imports}} diff --git a/github/gen-stringify-test.go b/github/gen-stringify-test.go index b78edad97b..71783fe578 100644 --- a/github/gen-stringify-test.go +++ b/github/gen-stringify-test.go @@ -352,7 +352,19 @@ func (t *templateData) dump() error { } logf("Writing %v...", t.filename) - return ioutil.WriteFile(t.filename, clean, 0644) + if err := os.Chmod(t.filename, 0644); err != nil { + return fmt.Errorf("os.Chmod(%q, 0644): %v", t.filename, err) + } + + if err := ioutil.WriteFile(t.filename, clean, 0444); err != nil { + return err + } + + if err := os.Chmod(t.filename, 0444); err != nil { + return fmt.Errorf("os.Chmod(%q, 0444): %v", t.filename, err) + } + + return nil } func newStructField(receiverType, fieldName, fieldType, zeroValue string, namedStruct bool) *structField { @@ -379,6 +391,8 @@ const source = `// Copyright {{.Year}} The go-github AUTHORS. All rights reserve // license that can be found in the LICENSE file. // Code generated by gen-stringify-tests; DO NOT EDIT. +// Instead, please run "go generate ./..." as described here: +// https://github.com/google/go-github/blob/master/CONTRIBUTING.md#submitting-a-patch package {{ $package := .Package}}{{$package}} {{with .Imports}} diff --git a/github/github-accessors.go b/github/github-accessors.go index cad631db5f..ecb473bba4 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -4,6 +4,8 @@ // license that can be found in the LICENSE file. // Code generated by gen-accessors; DO NOT EDIT. +// Instead, please run "go generate ./..." as described here: +// https://github.com/google/go-github/blob/master/CONTRIBUTING.md#submitting-a-patch package github diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index a796fe0554..d41a90b596 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -4,6 +4,8 @@ // license that can be found in the LICENSE file. // Code generated by gen-accessors; DO NOT EDIT. +// Instead, please run "go generate ./..." as described here: +// https://github.com/google/go-github/blob/master/CONTRIBUTING.md#submitting-a-patch package github diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 26cfd82cfa..743b2d1776 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -4,6 +4,8 @@ // license that can be found in the LICENSE file. // Code generated by gen-stringify-tests; DO NOT EDIT. +// Instead, please run "go generate ./..." as described here: +// https://github.com/google/go-github/blob/master/CONTRIBUTING.md#submitting-a-patch package github