fix file mode on lock file (#27205)

Signed-off-by: Anthony Sottile <asottile@umich.edu>
This commit is contained in:
Anthony Sottile 2020-12-18 08:51:59 -08:00 committed by GitHub
parent 235c141565
commit 8cd72e51cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -2,7 +2,6 @@ package depsfile
import ( import (
"fmt" "fmt"
"os"
"sort" "sort"
"github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2"
@ -134,7 +133,7 @@ func SaveLocksToFile(locks *Locks, filename string) tfdiags.Diagnostics {
newContent := f.Bytes() newContent := f.Bytes()
err := replacefile.AtomicWriteFile(filename, newContent, os.ModePerm) err := replacefile.AtomicWriteFile(filename, newContent, 0644)
if err != nil { if err != nil {
diags = diags.Append(tfdiags.Sourceless( diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error, tfdiags.Error,

View File

@ -232,6 +232,14 @@ func TestSaveLocksToFile(t *testing.T) {
t.Fatalf("unexpected errors\n%s", diags.Err().Error()) t.Fatalf("unexpected errors\n%s", diags.Err().Error())
} }
fileInfo, err := os.Stat(filename)
if err != nil {
t.Fatalf(err.Error())
}
if mode := fileInfo.Mode(); mode&0111 != 0 {
t.Fatalf("Expected lock file to be non-executable: %o", mode)
}
gotContentBytes, err := ioutil.ReadFile(filename) gotContentBytes, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {
t.Fatalf(err.Error()) t.Fatalf(err.Error())