(statusFile string, content string)
| 1000 | } |
| 1001 | |
| 1002 | func createStatusFileWithContent(statusFile string, content string) error { |
| 1003 | dir := filepath.Dir(statusFile) |
| 1004 | tmpFile, err := os.CreateTemp(dir, filepath.Base(statusFile)+".*.tmp") |
| 1005 | if err != nil { |
| 1006 | return fmt.Errorf("failed to create temporary status file: %w", err) |
| 1007 | } |
| 1008 | _, err = tmpFile.WriteString(content) |
| 1009 | tmpFile.Close() |
| 1010 | if err != nil { |
| 1011 | return fmt.Errorf("failed to write temporary status file: %w", err) |
| 1012 | } |
| 1013 | defer func() { |
| 1014 | //nolint:gosec |
| 1015 | _ = os.Remove(tmpFile.Name()) |
| 1016 | }() |
| 1017 | |
| 1018 | //nolint:gosec |
| 1019 | if err := os.Rename(tmpFile.Name(), statusFile); err != nil { |
| 1020 | return fmt.Errorf("error moving temporary file to '%s': %w", statusFile, err) |
| 1021 | } |
| 1022 | return nil |
| 1023 | } |
| 1024 | |
| 1025 | func deleteStatusFile(statusFile string) error { |
| 1026 | err := os.Remove(statusFile) |
no test coverage detected