mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
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
This commit is contained in:
@@ -830,6 +830,7 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
|
|||||||
|
|
||||||
changedPaths := struct {
|
changedPaths := struct {
|
||||||
changedFiles []*paths.Path
|
changedFiles []*paths.Path
|
||||||
|
addedFiles []*paths.Path
|
||||||
changedDirs []*paths.Path
|
changedDirs []*paths.Path
|
||||||
deleted []*paths.Path
|
deleted []*paths.Path
|
||||||
}{}
|
}{}
|
||||||
@@ -896,13 +897,15 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
|
|||||||
changedPaths.deleted = append(changedPaths.deleted, pss...)
|
changedPaths.deleted = append(changedPaths.deleted, pss...)
|
||||||
} else if ev.isChangedDir {
|
} else if ev.isChangedDir {
|
||||||
changedPaths.changedDirs = append(changedPaths.changedDirs, pss...)
|
changedPaths.changedDirs = append(changedPaths.changedDirs, pss...)
|
||||||
|
} else if ev.added {
|
||||||
|
changedPaths.addedFiles = append(changedPaths.addedFiles, pss...)
|
||||||
} else {
|
} else {
|
||||||
changedPaths.changedFiles = append(changedPaths.changedFiles, pss...)
|
changedPaths.changedFiles = append(changedPaths.changedFiles, pss...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the most specific identity possible.
|
// Find the most specific identity possible.
|
||||||
handleChange := func(pathInfo *paths.Path, delete, isDir bool) {
|
handleChange := func(pathInfo *paths.Path, delete, add, isDir bool) {
|
||||||
switch pathInfo.Component() {
|
switch pathInfo.Component() {
|
||||||
case files.ComponentFolderContent:
|
case files.ComponentFolderContent:
|
||||||
logger.Println("Source changed", pathInfo.Path())
|
logger.Println("Source changed", pathInfo.Path())
|
||||||
@@ -963,7 +966,10 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, structural: delete, isDir: isDir})
|
structural := delete
|
||||||
|
structural = structural || (add && pathInfo.IsLeafBundle())
|
||||||
|
|
||||||
|
addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, structural: structural, isDir: isDir})
|
||||||
|
|
||||||
case files.ComponentFolderLayouts:
|
case files.ComponentFolderLayouts:
|
||||||
tmplChanged = true
|
tmplChanged = true
|
||||||
@@ -1019,6 +1025,7 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
|
|||||||
}
|
}
|
||||||
|
|
||||||
changedPaths.deleted = removeDuplicatePaths(changedPaths.deleted)
|
changedPaths.deleted = removeDuplicatePaths(changedPaths.deleted)
|
||||||
|
changedPaths.addedFiles = removeDuplicatePaths(changedPaths.addedFiles)
|
||||||
changedPaths.changedFiles = removeDuplicatePaths(changedPaths.changedFiles)
|
changedPaths.changedFiles = removeDuplicatePaths(changedPaths.changedFiles)
|
||||||
|
|
||||||
h.Log.Trace(logg.StringFunc(func() string {
|
h.Log.Trace(logg.StringFunc(func() string {
|
||||||
@@ -1029,6 +1036,11 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
|
|||||||
sb.WriteString("path: " + p.Path())
|
sb.WriteString("path: " + p.Path())
|
||||||
sb.WriteString("\n")
|
sb.WriteString("\n")
|
||||||
}
|
}
|
||||||
|
sb.WriteString("Added:\n")
|
||||||
|
for _, p := range changedPaths.addedFiles {
|
||||||
|
sb.WriteString("path: " + p.Path())
|
||||||
|
sb.WriteString("\n")
|
||||||
|
}
|
||||||
sb.WriteString("Changed:\n")
|
sb.WriteString("Changed:\n")
|
||||||
for _, p := range changedPaths.changedFiles {
|
for _, p := range changedPaths.changedFiles {
|
||||||
sb.WriteString("path: " + p.Path())
|
sb.WriteString("path: " + p.Path())
|
||||||
@@ -1074,15 +1086,19 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, deleted := range changedPaths.deleted {
|
for _, deleted := range changedPaths.deleted {
|
||||||
handleChange(deleted, true, false)
|
handleChange(deleted, true, false, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, id := range changedPaths.addedFiles {
|
||||||
|
handleChange(id, false, true, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id := range changedPaths.changedFiles {
|
for _, id := range changedPaths.changedFiles {
|
||||||
handleChange(id, false, false)
|
handleChange(id, false, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id := range changedPaths.changedDirs {
|
for _, id := range changedPaths.changedDirs {
|
||||||
handleChange(id, false, true)
|
handleChange(id, false, false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id := range changes {
|
for _, id := range changes {
|
||||||
|
@@ -125,6 +125,24 @@ func TestRebuildEditTextFileInLeafBundle(t *testing.T) {
|
|||||||
b.AssertRenderCountContent(0)
|
b.AssertRenderCountContent(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRebuildAddingALeaffBundleIssue13925(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
b := TestRunning(t, rebuildFilesSimple)
|
||||||
|
|
||||||
|
b.AddFiles(
|
||||||
|
"content/mysection/mysectionbundle2/index.md", "",
|
||||||
|
"content/mysection/mysectionbundle2/mysectionbundletext.txt", "mysectionbundletext.txt").Build()
|
||||||
|
|
||||||
|
b.AssertFileContent("public/mysection/mysectionbundle2/index.html", "Len Resources: 1|")
|
||||||
|
|
||||||
|
b.AddFiles(
|
||||||
|
"content/mynewsection/_index.md", "",
|
||||||
|
"content/mynewsection/mynewsectiontext.txt", "foo").Build()
|
||||||
|
|
||||||
|
b.AssertFileContent("public/mynewsection/index.html", "Len Resources: 1|")
|
||||||
|
}
|
||||||
|
|
||||||
func TestRebuildEditTextFileInShortcode(t *testing.T) {
|
func TestRebuildEditTextFileInShortcode(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
for range 3 {
|
for range 3 {
|
||||||
|
Reference in New Issue
Block a user