summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-20 18:24:33 -0400
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-21 00:06:49 -0400
commitcf05f1bc0a03d02a07ee28d2d25b828f23371327 (patch)
tree3486473fc7b1c4572dceca57f9944de021584ea5
parent24033d5f468f64c2ab7061d5cf3354d44b60d22d (diff)
gen-posix: Atomic updates
-rw-r--r--Makefile2
-rw-r--r--cmd/gen-posix/main.go28
2 files changed, 24 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 56f4be3..30107bb 100644
--- a/Makefile
+++ b/Makefile
@@ -38,7 +38,7 @@ public/imworkingon/imworkingon.css: public/imworkingon/imworkingon.scss
public/posix/index.html: FORCE
mkdir -p $(@D)
- go run ./cmd/gen-posix >$@
+ go run ./cmd/gen-posix
# generate = checked in to Git #################################################
diff --git a/cmd/gen-posix/main.go b/cmd/gen-posix/main.go
index 66a2588..354fd3f 100644
--- a/cmd/gen-posix/main.go
+++ b/cmd/gen-posix/main.go
@@ -1,6 +1,8 @@
package main
import (
+ "bytes"
+ "fmt"
"html/template"
"os"
)
@@ -179,12 +181,28 @@ var tmpl = `{{define "document"}}{{if .}}
</html>
`
-func main() {
- err := template.Must(template.New("page").Parse(tmpl)).Execute(os.Stdout, map[string]interface{}{
+func mainWithError() error {
+ tmpl := template.Must(template.New("page").Parse(tmpl))
+
+ var out bytes.Buffer
+ if err := tmpl.Execute(&out, map[string]interface{}{
"Vendors": Vendors,
"Editions": Editions,
- })
- if err != nil {
- panic(err)
+ }); err != nil {
+ return err
+ }
+ if err := os.WriteFile("public/posix/index.new.html", out.Bytes(), 0666); err != nil {
+ return err
+ }
+ if err := os.Rename("public/posix/index.new.html", "public/posix/index.html"); err != nil {
+ return err
+ }
+ return nil
+}
+
+func main() {
+ if err := mainWithError(); err != nil {
+ fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
+ os.Exit(1)
}
}