diff --git a/main.go b/main.go index 02cb0db..a41dde9 100644 --- a/main.go +++ b/main.go @@ -233,14 +233,23 @@ func filterDiffOutput(diffOutput, cname string, ignores []string) (string, error } func writeToFile(filename, content string) error { - file, err := os.Create(filename) + tempFile, err := os.CreateTemp("", "filtered_output") if err != nil { - return err + return fmt.Errorf("error creating temporary file: %s", err) } - defer file.Close() + defer os.Remove(tempFile.Name()) // Ensure the temporary file is removed - _, err = file.WriteString(content) - return err + _, err = tempFile.WriteString(content) + if err != nil { + return fmt.Errorf("error writing to temporary file: %s", err) + } + + err = copyFile(tempFile.Name(), filename) + if err != nil { + return fmt.Errorf("error copying temporary file to final destination: %s", err) + } + + return nil } func sendNotification(content string) error {