func copyFile()

in cmd/release/minor/projects/projects.go [90:120]


func copyFile(prevReleaseBranchFilePath, nextReleaseBranchFilePath string) error {
	existingFile, err := os.Open(prevReleaseBranchFilePath)
	if err != nil {
		return fmt.Errorf("opening file %s to copy: %w", prevReleaseBranchFilePath, err)
	}
	defer existingFile.Close()

	newFile, err := os.Create(nextReleaseBranchFilePath)
	if err != nil {
		return fmt.Errorf("creating file %s to write to as a copy: %w", nextReleaseBranchFilePath, err)
	}
	defer newFile.Close()

	if filepath.Base(existingFile.Name()) == "CHECKSUMS" {
		scanner := bufio.NewScanner(existingFile)
		for scanner.Scan() {
			updatedLine := strings.ReplaceAll(scanner.Text(), prevReleaseBranch, nextReleaseBranch)
			if _, err = fmt.Fprintln(newFile, updatedLine); err != nil {
				return fmt.Errorf("modifying CHECKSUM file: %w", err)
			}
		}
		if err = scanner.Err(); err != nil {
			return fmt.Errorf("scanning CHECKSUMS: %w", err)
		}
	} else {
		if _, err = io.Copy(newFile, existingFile); err != nil {
			return fmt.Errorf("copying files: %w", err)
		}
	}
	return nil
}