Skip to content

Commit 13b43e6

Browse files
committed
Fix server rebuild when adding a new leaf bundle with resources in one go
E.g. `cp -r`. Note that this was not an issue if you first created the bundle, waited, and then created the resource(s). Fixes #13925
1 parent bff4ddd commit 13b43e6

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

‎hugolib/hugo_sites_build.go‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
830830

831831
changedPaths := struct {
832832
changedFiles []*paths.Path
833+
addedFiles []*paths.Path
833834
changedDirs []*paths.Path
834835
deleted []*paths.Path
835836
}{}
@@ -896,13 +897,15 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
896897
changedPaths.deleted = append(changedPaths.deleted, pss...)
897898
} else if ev.isChangedDir {
898899
changedPaths.changedDirs = append(changedPaths.changedDirs, pss...)
900+
} else if ev.added {
901+
changedPaths.addedFiles = append(changedPaths.addedFiles, pss...)
899902
} else {
900903
changedPaths.changedFiles = append(changedPaths.changedFiles, pss...)
901904
}
902905
}
903906

904907
// Find the most specific identity possible.
905-
handleChange := func(pathInfo *paths.Path, delete, isDir bool) {
908+
handleChange := func(pathInfo *paths.Path, delete, add, isDir bool) {
906909
switch pathInfo.Component() {
907910
case files.ComponentFolderContent:
908911
logger.Println("Source changed", pathInfo.Path())
@@ -963,7 +966,10 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
963966
}
964967
}
965968

966-
addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, structural: delete, isDir: isDir})
969+
structural := delete
970+
structural = structural || (add && pathInfo.IsLeafBundle())
971+
972+
addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, structural: structural, isDir: isDir})
967973

968974
case files.ComponentFolderLayouts:
969975
tmplChanged = true
@@ -1019,6 +1025,7 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
10191025
}
10201026

10211027
changedPaths.deleted = removeDuplicatePaths(changedPaths.deleted)
1028+
changedPaths.addedFiles = removeDuplicatePaths(changedPaths.addedFiles)
10221029
changedPaths.changedFiles = removeDuplicatePaths(changedPaths.changedFiles)
10231030

10241031
h.Log.Trace(logg.StringFunc(func() string {
@@ -1029,6 +1036,11 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
10291036
sb.WriteString("path: " + p.Path())
10301037
sb.WriteString("\n")
10311038
}
1039+
sb.WriteString("Added:\n")
1040+
for _, p := range changedPaths.addedFiles {
1041+
sb.WriteString("path: " + p.Path())
1042+
sb.WriteString("\n")
1043+
}
10321044
sb.WriteString("Changed:\n")
10331045
for _, p := range changedPaths.changedFiles {
10341046
sb.WriteString("path: " + p.Path())
@@ -1074,15 +1086,19 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
10741086
}
10751087

10761088
for _, deleted := range changedPaths.deleted {
1077-
handleChange(deleted, true, false)
1089+
handleChange(deleted, true, false, false)
1090+
}
1091+
1092+
for _, id := range changedPaths.addedFiles {
1093+
handleChange(id, false, true, false)
10781094
}
10791095

10801096
for _, id := range changedPaths.changedFiles {
1081-
handleChange(id, false, false)
1097+
handleChange(id, false, false, false)
10821098
}
10831099

10841100
for _, id := range changedPaths.changedDirs {
1085-
handleChange(id, false, true)
1101+
handleChange(id, false, false, true)
10861102
}
10871103

10881104
for _, id := range changes {

‎hugolib/rebuild_test.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ func TestRebuildEditTextFileInLeafBundle(t *testing.T) {
125125
b.AssertRenderCountContent(0)
126126
}
127127

128+
func TestRebuildAddingALeaffBundleIssue13925(t *testing.T) {
129+
t.Parallel()
130+
131+
b := TestRunning(t, rebuildFilesSimple)
132+
133+
b.AddFiles(
134+
"content/mysection/mysectionbundle2/index.md", "",
135+
"content/mysection/mysectionbundle2/mysectionbundletext.txt", "mysectionbundletext.txt").Build()
136+
137+
b.AssertFileContent("public/mysection/mysectionbundle2/index.html", "Len Resources: 1|")
138+
139+
b.AddFiles(
140+
"content/mynewsection/_index.md", "",
141+
"content/mynewsection/mynewsectiontext.txt", "foo").Build()
142+
143+
b.AssertFileContent("public/mynewsection/index.html", "Len Resources: 1|")
144+
}
145+
128146
func TestRebuildEditTextFileInShortcode(t *testing.T) {
129147
t.Parallel()
130148
for range 3 {

0 commit comments

Comments
 (0)