From 5cef3624289c11b21c661b314973bc85183bc3c6 Mon Sep 17 00:00:00 2001 From: t Date: Sat, 11 Jul 2026 22:58:41 -0600 Subject: 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 --- main_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'main_test.go') 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") + } +} -- cgit v1.3