diff options
Diffstat (limited to 'modules/charset')
-rw-r--r-- | modules/charset/ambiguous/generate.go | 11 | ||||
-rw-r--r-- | modules/charset/invisible/generate.go | 11 |
2 files changed, 22 insertions, 0 deletions
diff --git a/modules/charset/ambiguous/generate.go b/modules/charset/ambiguous/generate.go index 43cdb217a7..7dd2821aae 100644 --- a/modules/charset/ambiguous/generate.go +++ b/modules/charset/ambiguous/generate.go @@ -110,6 +110,17 @@ func runTemplate(t *template.Template, filename string, data interface{}) error verbosef("Bad source:\n%s", buf.String()) return fmt.Errorf("unable to format source: %w", err) } + + old, err := os.ReadFile(filename) + if err != nil && !os.IsNotExist(err) { + return fmt.Errorf("failed to read old file %s because %w", filename, err) + } else if err == nil { + if bytes.Equal(bs, old) { + // files are the same don't rewrite it. + return nil + } + } + file, err := os.Create(filename) if err != nil { return fmt.Errorf("failed to create file %s because %w", filename, err) diff --git a/modules/charset/invisible/generate.go b/modules/charset/invisible/generate.go index 230ff0b832..39eddd58dd 100644 --- a/modules/charset/invisible/generate.go +++ b/modules/charset/invisible/generate.go @@ -63,6 +63,17 @@ func runTemplate(t *template.Template, filename string, data interface{}) error verbosef("Bad source:\n%s", buf.String()) return fmt.Errorf("unable to format source: %w", err) } + + old, err := os.ReadFile(filename) + if err != nil && !os.IsNotExist(err) { + return fmt.Errorf("failed to read old file %s because %w", filename, err) + } else if err == nil { + if bytes.Equal(bs, old) { + // files are the same don't rewrite it. + return nil + } + } + file, err := os.Create(filename) if err != nil { return fmt.Errorf("failed to create file %s because %w", filename, err) |