summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-05-22 15:29:27 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-05-22 16:27:19 +0200
commit4cac5f5e306b6c301258eb9936094eb910264c9a (patch)
tree2c1205f7d9e60475ebc3534aaecea47ca535c176 /hugolib
parent2c3d4dfb745799b5de11f9ec0463a4ace19e97de (diff)
Avoid writing to hugo_stats.json when there are no changes
Fixes #10985
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/hugo_sites_build.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index f86d425b3..3464385d3 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -455,12 +455,21 @@ func (h *HugoSites) writeBuildStats() error {
HTMLElements: *htmlElements,
}
+ const hugoStatsName = "hugo_stats.json"
+
js, err := json.MarshalIndent(stats, "", " ")
if err != nil {
return err
}
- filename := filepath.Join(h.Configs.LoadingInfo.BaseConfig.WorkingDir, "hugo_stats.json")
+ filename := filepath.Join(h.Configs.LoadingInfo.BaseConfig.WorkingDir, hugoStatsName)
+
+ if existingContent, err := afero.ReadFile(hugofs.Os, filename); err == nil {
+ // Check if the content has changed.
+ if bytes.Equal(existingContent, js) {
+ return nil
+ }
+ }
// Make sure it's always written to the OS fs.
if err := afero.WriteFile(hugofs.Os, filename, js, 0666); err != nil {