write the to / . controls if the file is created or content will be appended
(outputDir string, name string, data string, appendData bool)
| 718 | |
| 719 | // write the <data> to <output-dir>/<name>. <appendData> controls if the file is created or content will be appended |
| 720 | func writeToFile(outputDir string, name string, data string, appendData bool) error { |
| 721 | outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator)) |
| 722 | |
| 723 | err := ensureDirectoryForFile(outfileName) |
| 724 | if err != nil { |
| 725 | return err |
| 726 | } |
| 727 | |
| 728 | f, err := createOrOpenFile(outfileName, appendData) |
| 729 | if err != nil { |
| 730 | return err |
| 731 | } |
| 732 | |
| 733 | defer f.Close() |
| 734 | |
| 735 | _, err = fmt.Fprintf(f, "---\n# Source: %s\n%s\n", name, data) |
| 736 | |
| 737 | if err != nil { |
| 738 | return err |
| 739 | } |
| 740 | |
| 741 | fmt.Printf("wrote %s\n", outfileName) |
| 742 | return nil |
| 743 | } |
| 744 | |
| 745 | func createOrOpenFile(filename string, appendData bool) (*os.File, error) { |
| 746 | if appendData { |
no test coverage detected
searching dependent graphs…