From 744c3b70fa590345f6c1de715e2a572f184091c4 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 19 Nov 2024 10:56:44 +0200 Subject: initial inline to file path extraction --- internal/oi/oi.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'internal/oi') 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) +} -- cgit v1.2.3