Skip to content

Commit 3cf11db

Browse files
Ajit Pratap SinghAjit Pratap Singh
authored andcommitted
fix: preserve original file permissions in lint auto-fix
- Replace hardcoded 0600 with preservation of original file permissions - Falls back to 0644 if stat fails - Prevents breaking team workflows where files need broader permissions - Addresses security/usability issue identified in PR #111 code review
1 parent 94e8bf8 commit 3cf11db

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

cmd/gosqlx/cmd/lint.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,16 @@ func lintRun(cmd *cobra.Command, args []string) error {
120120
}
121121
}
122122

123-
// Write back if modified
123+
// Write back if modified, preserving original file permissions
124124
if modified {
125-
if err := os.WriteFile(fileResult.Filename, []byte(fixed), 0600); err != nil {
125+
// Get original file permissions
126+
fileInfo, statErr := os.Stat(fileResult.Filename)
127+
perm := os.FileMode(0644) // Default fallback permission
128+
if statErr == nil {
129+
perm = fileInfo.Mode()
130+
}
131+
132+
if err := os.WriteFile(fileResult.Filename, []byte(fixed), perm); err != nil {
126133
fmt.Fprintf(cmd.ErrOrStderr(), "Error writing %s: %v\n", fileResult.Filename, err)
127134
continue
128135
}

0 commit comments

Comments
 (0)