writeFileWithStatus() which shows 'Creating' for new, 'Updating' for changed and 'Unchanged' for files that won't change

This commit is contained in:
Pim van Pelt
2025-08-25 11:51:41 +02:00
parent c9c1e81619
commit 38fe915b37
5 changed files with 65 additions and 71 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"bytes"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
@@ -136,27 +137,25 @@ func generateHTML(yamlFile string) {
for _, logEntry := range config.Logs {
indexPath := fmt.Sprintf("%s/index.html", logEntry.LocalDirectory)
file, err := os.Create(indexPath)
// Execute template to buffer
var buf bytes.Buffer
err := tmpl.Execute(&buf, config)
if err != nil {
log.Fatalf("Failed to create %s: %v", indexPath, err)
log.Fatalf("Failed to execute HTML template for %s: %v", indexPath, err)
}
err = tmpl.Execute(file, config)
// Write file with status
err = writeFileWithStatus(indexPath, buf.Bytes())
if err != nil {
file.Close()
log.Fatalf("Failed to write HTML to %s: %v", indexPath, err)
}
file.Close()
fmt.Printf("Generated %s\n", indexPath)
// Generate log.v3.json for this log
jsonPath := filepath.Join(logEntry.LocalDirectory, "log.v3.json")
err = generateLogJSON(logEntry, jsonPath)
err = generateLogJSONWithStatus(logEntry, jsonPath)
if err != nil {
log.Fatalf("Failed to generate %s: %v", jsonPath, err)
}
fmt.Printf("Generated %s\n", jsonPath)
}
}
@@ -210,7 +209,7 @@ func computeKeyInfo(logEntry *Log) error {
return nil
}
func generateLogJSON(logEntry Log, outputPath string) error {
func generateLogJSONWithStatus(logEntry Log, outputPath string) error {
logJSON := LogV3JSON{
Description: fmt.Sprintf("%s.log.ct.ipng.ch", logEntry.ShortName),
SubmissionURL: fmt.Sprintf("%s/", logEntry.SubmissionPrefix),
@@ -229,10 +228,5 @@ func generateLogJSON(logEntry Log, outputPath string) error {
return fmt.Errorf("failed to marshal JSON: %v", err)
}
err = os.WriteFile(outputPath, jsonData, 0644)
if err != nil {
return fmt.Errorf("failed to write JSON file: %v", err)
}
return nil
return writeFileWithStatus(outputPath, jsonData)
}