diff --git a/changelogs/unreleased/attributes-perm.yml b/changelogs/unreleased/attributes-perm.yml new file mode 100644 index 0000000000000000000000000000000000000000..03bf4e4c00a89837c25644b5cae9b47ab3031651 --- /dev/null +++ b/changelogs/unreleased/attributes-perm.yml @@ -0,0 +1,5 @@ +--- +title: Set permission of attributes file to `0644` +merge_request: 1466 +author: @njkevlani +type: added diff --git a/internal/service/repository/apply_gitattributes.go b/internal/service/repository/apply_gitattributes.go index 4f52a06be8549f07ecafbb56d9551577c7af9808..c302ce170c7e70d075345c10345ac1b7efe69fc7 100644 --- a/internal/service/repository/apply_gitattributes.go +++ b/internal/service/repository/apply_gitattributes.go @@ -16,6 +16,8 @@ import ( "google.golang.org/grpc/status" ) +const attributesFileMode os.FileMode = 0644 + func applyGitattributes(c *catfile.Batch, repoPath string, revision []byte) error { infoPath := path.Join(repoPath, "info") attributesPath := path.Join(infoPath, "attributes") @@ -68,6 +70,11 @@ func applyGitattributes(c *catfile.Batch, repoPath string, revision []byte) erro return err } + // Change the permission of tempFile as the permission of file attributesPath + if err := os.Chmod(tempFile.Name(), attributesFileMode); err != nil { + return err + } + // Rename temp file and return the result return os.Rename(tempFile.Name(), attributesPath) } diff --git a/internal/service/repository/apply_gitattributes_test.go b/internal/service/repository/apply_gitattributes_test.go index e82968530d8a0649df931a4981fec3dbc8db1041..0dd242b92f999ab1b422028893b32d6a035a1020 100644 --- a/internal/service/repository/apply_gitattributes_test.go +++ b/internal/service/repository/apply_gitattributes_test.go @@ -149,6 +149,11 @@ func assertGitattributesApplied(t *testing.T, client gitalypb.RepositoryServiceC t.Error(err) } + if info, err := os.Stat(attributesPath); err == nil { + actualFileMode := info.Mode() + assert.Equal(t, attributesFileMode, actualFileMode) + } + assert.Equal(t, expectedContents, contents) } }