MCPcopy Create free account
hub / github.com/NVIDIA/gpu-operator / createStatusFileWithContent

Function createStatusFileWithContent

cmd/nvidia-validator/main.go:1002–1023  ·  view source on GitHub ↗
(statusFile string, content string)

Source from the content-addressed store, hash-verified

1000}
1001
1002func 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
1025func deleteStatusFile(statusFile string) error {
1026 err := os.Remove(statusFile)

Callers 4

createStatusFileMethod · 0.85
validateMethod · 0.85
validateMethod · 0.85
validateMethod · 0.85

Calls 1

NameMethod · 0.65

Tested by

no test coverage detected