(filename string, summary syncSummary)
| 45 | } |
| 46 | |
| 47 | func persistSummary(filename string, summary syncSummary) error { |
| 48 | // if filename is not specified then we don't need to persist the summary and can return |
| 49 | if filename == "" { |
| 50 | return nil |
| 51 | } |
| 52 | err := checkFilePath(filename) |
| 53 | if err != nil { |
| 54 | return fmt.Errorf("failed to validate summary file path: %w", err) |
| 55 | } |
| 56 | dataBytes, err := json.Marshal(summary) |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | dataBytes = append(dataBytes, []byte("\n")...) |
| 61 | err = appendToFile(filename, dataBytes) |
| 62 | if err != nil { |
| 63 | return fmt.Errorf("failed to append summary to file: %w", err) |
| 64 | } |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | func appendToFile(fileName string, data []byte) error { |
| 69 | f, err := os.OpenFile(fileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) |
no test coverage detected