writeFileWithStatus() which shows 'Creating' for new, 'Updating' for changed and 'Unchanged' for files that won't change
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -25,11 +24,10 @@ func generateEnv(yamlFile string) {
|
||||
|
||||
// Create combined roots.pem file
|
||||
rootsPemPath := filepath.Join(logEntry.LocalDirectory, "roots.pem")
|
||||
err := createCombinedRootsPem(config.Roots, logEntry.ExtraRoots, rootsPemPath)
|
||||
err := createCombinedRootsPemWithStatus(config.Roots, logEntry.ExtraRoots, rootsPemPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create %s: %v", rootsPemPath, err)
|
||||
}
|
||||
fmt.Printf("Generated %s\n", rootsPemPath)
|
||||
|
||||
// Build TESSERACT_ARGS string
|
||||
args := []string{
|
||||
@@ -47,50 +45,32 @@ func generateEnv(yamlFile string) {
|
||||
tesseractArgs := strings.Join(args, " ")
|
||||
envContent := fmt.Sprintf("TESSERACT_ARGS=\"%s\"\nOTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318\n", tesseractArgs)
|
||||
|
||||
err = os.WriteFile(envPath, []byte(envContent), 0644)
|
||||
err = writeFileWithStatus(envPath, []byte(envContent))
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to write %s: %v", envPath, err)
|
||||
}
|
||||
|
||||
fmt.Printf("Generated %s\n", envPath)
|
||||
}
|
||||
}
|
||||
|
||||
func createCombinedRootsPem(rootsFile, extraRootsFile, outputPath string) error {
|
||||
// Create output file
|
||||
outputFile, err := os.Create(outputPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create output file: %v", err)
|
||||
}
|
||||
defer outputFile.Close()
|
||||
|
||||
// Copy main roots file
|
||||
func createCombinedRootsPemWithStatus(rootsFile, extraRootsFile, outputPath string) error {
|
||||
// Read main roots file
|
||||
var combinedContent []byte
|
||||
if rootsFile != "" {
|
||||
rootsData, err := os.Open(rootsFile)
|
||||
rootsData, err := os.ReadFile(rootsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open roots file %s: %v", rootsFile, err)
|
||||
}
|
||||
defer rootsData.Close()
|
||||
|
||||
_, err = io.Copy(outputFile, rootsData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to copy roots file: %v", err)
|
||||
return fmt.Errorf("failed to read roots file %s: %v", rootsFile, err)
|
||||
}
|
||||
combinedContent = append(combinedContent, rootsData...)
|
||||
}
|
||||
|
||||
// Append extra roots file if it exists
|
||||
if extraRootsFile != "" {
|
||||
extraRootsData, err := os.Open(extraRootsFile)
|
||||
extraRootsData, err := os.ReadFile(extraRootsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open extra roots file %s: %v", extraRootsFile, err)
|
||||
}
|
||||
defer extraRootsData.Close()
|
||||
|
||||
_, err = io.Copy(outputFile, extraRootsData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to copy extra roots file: %v", err)
|
||||
return fmt.Errorf("failed to read extra roots file %s: %v", extraRootsFile, err)
|
||||
}
|
||||
combinedContent = append(combinedContent, extraRootsData...)
|
||||
}
|
||||
|
||||
return nil
|
||||
return writeFileWithStatus(outputPath, combinedContent)
|
||||
}
|
||||
|
Reference in New Issue
Block a user