(src, dst string)
| 9 | ) |
| 10 | |
| 11 | func CopyConfigTemplate(src, dst string) error { |
| 12 | in, err := os.Open(src) |
| 13 | if err != nil { |
| 14 | return err |
| 15 | } |
| 16 | defer func() { |
| 17 | if errClose := in.Close(); errClose != nil { |
| 18 | log.WithError(errClose).Warn("failed to close source config file") |
| 19 | } |
| 20 | }() |
| 21 | |
| 22 | if err = os.MkdirAll(filepath.Dir(dst), 0o700); err != nil { |
| 23 | return err |
| 24 | } |
| 25 | |
| 26 | out, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600) |
| 27 | if err != nil { |
| 28 | return err |
| 29 | } |
| 30 | defer func() { |
| 31 | if errClose := out.Close(); errClose != nil { |
| 32 | log.WithError(errClose).Warn("failed to close destination config file") |
| 33 | } |
| 34 | }() |
| 35 | |
| 36 | if _, err = io.Copy(out, in); err != nil { |
| 37 | return err |
| 38 | } |
| 39 | return out.Sync() |
| 40 | } |
no test coverage detected