Skip to content

Commit

Permalink
Fix false path warnings with resources.PostProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jun 26, 2023
1 parent bac03f4 commit a03a1a3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions hugofs/createcounting_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Reseter interface {
// DuplicatesReporter reports about duplicate filenames.
type DuplicatesReporter interface {
ReportDuplicates() string
Stop()
}

var (
Expand Down Expand Up @@ -67,11 +68,19 @@ func (c *createCountingFs) ReportDuplicates() string {
return strings.Join(dupes, ", ")
}

func (c *createCountingFs) Stop() {
c.mu.Lock()
defer c.mu.Unlock()
c.stopped = true
}

// createCountingFs counts filenames of created files or files opened
// for writing.
type createCountingFs struct {
afero.Fs

stopped bool

mu sync.Mutex
fileCount map[string]int
}
Expand All @@ -86,6 +95,9 @@ func (c *createCountingFs) Reset() {
func (fs *createCountingFs) onCreate(filename string) {
fs.mu.Lock()
defer fs.mu.Unlock()
if fs.stopped {
return
}

fs.fileCount[filename] = fs.fileCount[filename] + 1
}
Expand Down
8 changes: 8 additions & 0 deletions hugolib/hugo_sites_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ func (h *HugoSites) render(l logg.LevelLogger, config *BuildCfg) error {
func (h *HugoSites) postProcess(l logg.LevelLogger) error {
defer h.timeTrack(l, time.Now(), "postProcess")

hugofs.WalkFilesystems(h.Fs.PublishDir, func(fs afero.Fs) bool {
if dfs, ok := fs.(hugofs.DuplicatesReporter); ok {
// We will rewrite to the same files, so we need to stop any duplicate counting.
dfs.Stop()
}
return false
})

// Make sure to write any build stats to disk first so it's available
// to the post processors.
if err := h.writeBuildStats(); err != nil {
Expand Down
22 changes: 22 additions & 0 deletions testscripts/unfinished/hugo__path-warnings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


hugo --printPathWarnings

! stdout 'Duplicate target paths'

-- hugo.toml --
-- assets/css/styles.css --
body {
background-color: #000;
}
-- content/p1.md --
-- content/p2.md --
-- content/p3.md --
-- layouts/index.html --
Home.
-- layouts/_default/single.html --
{{ $css := resources.Get "css/styles.css" }}
{{ $css := $css | minify | fingerprint | resources.PostProcess }}
CSS: {{ $css.RelPermalink }}
{{ .Title }}

0 comments on commit a03a1a3

Please sign in to comment.