fix(extgen): don't remove everything in the build directory now that there's no build subdir

This commit is contained in:
Alexandre Daubois
2025-11-14 09:56:30 +01:00
committed by Kévin Dunglas
parent 18946308fd
commit 4e6d67e0b4
2 changed files with 11 additions and 4 deletions

View File

@@ -50,10 +50,6 @@ func (g *Generator) Generate() error {
}
func (g *Generator) setupBuildDirectory() error {
if err := os.RemoveAll(g.BuildDir); err != nil {
return fmt.Errorf("removing build directory: %w", err)
}
return os.MkdirAll(g.BuildDir, 0755)
}

View File

@@ -4,6 +4,7 @@ import (
"bytes"
_ "embed"
"fmt"
"os"
"path/filepath"
"text/template"
@@ -30,6 +31,16 @@ type goTemplateData struct {
func (gg *GoFileGenerator) generate() error {
filename := filepath.Join(gg.generator.BuildDir, gg.generator.BaseName+".go")
if _, err := os.Stat(filename); err == nil {
backupFilename := filename + ".bak"
if err := os.Rename(filename, backupFilename); err != nil {
return fmt.Errorf("backing up existing Go file: %w", err)
}
gg.generator.SourceFile = backupFilename
}
content, err := gg.buildContent()
if err != nil {
return fmt.Errorf("building Go file content: %w", err)