diff options
| author | t <t@tjp.lol> | 2026-07-11 22:58:41 -0600 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-07-11 22:58:55 -0600 |
| commit | 5cef3624289c11b21c661b314973bc85183bc3c6 (patch) | |
| tree | 0ae89d9115b3922ac0503d7c6fcb089e78b2fcd7 /main_test.go | |
| parent | 10e19481611f21f8ad20986ecc1b9d8d7d89ff4d (diff) | |
improve build finalization
- fallback from file rename to copying on EXDEV, the signal that we
tried to rename a file onto another filesystem mount
- also check `bytes.Equal` and skip the final overwrite if nothing would
change - this preserves file mtime and therefore http caching
Diffstat (limited to 'main_test.go')
| -rw-r--r-- | main_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/main_test.go b/main_test.go index c4b0ec7..f2aae0a 100644 --- a/main_test.go +++ b/main_test.go @@ -361,3 +361,37 @@ func TestSortingFilteringSlicing(t *testing.T) { t.Fatal("slice") } } + +func TestUnchangedOutputsKeepMtime(t *testing.T) { + root := t.TempDir() + writeTestFile(t, root, "layout.tmpl", testLayouts()) + writeTestFile(t, root, "a.md", "# A\n\nbody\n") + writeTestFile(t, root, "b.md", "# B\n\nbody\n") + if err := build(root); err != nil { + t.Fatal(err) + } + old := time.Now().Add(-time.Hour) + for _, name := range []string{"a.html", "b.html"} { + if err := os.Chtimes(filepath.Join(root, name), old, old); err != nil { + t.Fatal(err) + } + } + writeTestFile(t, root, "b.md", "# B\n\nchanged\n") + if err := build(root); err != nil { + t.Fatal(err) + } + unchanged, err := os.Stat(filepath.Join(root, "a.html")) + if err != nil { + t.Fatal(err) + } + if !unchanged.ModTime().Equal(old) { + t.Errorf("unchanged output mtime bumped: %v", unchanged.ModTime()) + } + changed, err := os.Stat(filepath.Join(root, "b.html")) + if err != nil { + t.Fatal(err) + } + if changed.ModTime().Equal(old) { + t.Error("changed output mtime not updated") + } +} |
