diff options
| author | Paul Buetow <paul@buetow.org> | 2024-11-19 10:56:44 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-11-19 10:56:44 +0200 |
| commit | 744c3b70fa590345f6c1de715e2a572f184091c4 (patch) | |
| tree | d198cf86b5afe2fbc7af42fdb0b1262c2f5bc30c /internal/oi | |
| parent | f2318c4946db3ffd60a2b955e47660c2f77007df (diff) | |
initial inline to file path extraction
Diffstat (limited to 'internal/oi')
| -rw-r--r-- | internal/oi/oi.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/oi/oi.go b/internal/oi/oi.go index b2a0953..824c0bd 100644 --- a/internal/oi/oi.go +++ b/internal/oi/oi.go @@ -147,3 +147,18 @@ func SlurpAndTrim(filePath string) (string, error) { } return strings.TrimSpace(string(bytes)), nil } + +func WriteFile(filePath, content string) error { + tmpFilePath := fmt.Sprintf("%s.tmp", filePath) + file, err := os.OpenFile(tmpFilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + if err != nil { + return err + } + defer file.Close() + + _, err = file.WriteString(content) + if err != nil { + return err + } + return os.Rename(tmpFilePath, filePath) +} |
