Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fingerprint appended twice causing file name too long #12656

Closed
jloh opened this issue Jul 13, 2024 · 1 comment
Closed

Fingerprint appended twice causing file name too long #12656

jloh opened this issue Jul 13, 2024 · 1 comment
Assignees
Milestone

Comments

@jloh
Copy link
Contributor

jloh commented Jul 13, 2024

What version of Hugo are you using (hugo version)?

I normally use the extended edition, currently using the standard one.

$ hugo version
hugo v0.128.2-de36c1a95d28595d8243fd8b891665b069ed0850 darwin/arm64 BuildDate=2024-07-04T08:13:25Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes


Every now and then Hugo seems to append the fingerprint of a hashed image to it twice, this causes the server to fail because the resulting filename ends up being to long:

Change detected, rebuilding site (#11).
2024-07-13 23:00:45.163 +1000
Template changed /_default/list.html
ERROR open /Users/james/code/github/jloh/blog/public/posts/create-a-edgerouter-dmz/new_firewall_group.3ef0e068ae956523362daaab41a5c19413fc600293421b569d084e0ad28cae151f3c37908775cf8bb68b40a35ea70ab26f992eaed2bf19ad8898900b170e4444.3ef0e068ae956523362daaab41a5c19413fc600293421b569d084e0ad28cae151f3c37908775cf8bb68b40a35ea70ab26f992eaed2bf19ad8898900b170e4444.png: file name too long
ERROR open /Users/james/code/github/jloh/blog/public/posts/create-a-edgerouter-dmz/firewall_group_add_ranges.2135673415dc56dec230a31f866b42b22f535e25eddc4ab42d265509690184b1be03afc3020dc17c25ffd1e88c4346b29fd35dbdeb4ddbdf3b6e7809f48ac7f4.2135673415dc56dec230a31f866b42b22f535e25eddc4ab42d265509690184b1be03afc3020dc17c25ffd1e88c4346b29fd35dbdeb4ddbdf3b6e7809f48ac7f4.png: file name too long
ERROR open /Users/james/code/github/jloh/blog/public/posts/create-a-edgerouter-dmz/add_new_firewall_set.7465bafac167f2e5d84094403a821a040e8ebeaa484b296ef382d299c229f84196a01ee220ca7f4c3c4a78de2d10dccf66ec395b1f3ecfcac4127bb70a6fc478.7465bafac167f2e5d84094403a821a040e8ebeaa484b296ef382d299c229f84196a01ee220ca7f4c3c4a78de2d10dccf66ec395b1f3ecfcac4127bb70a6fc478.png: file name too long
ERROR open /Users/james/code/github/jloh/blog/public/posts/create-a-edgerouter-dmz/add_established_related_rule.83ac29f37d94588bf486c3656023249dc24daa583dfbaa701f35cea94b0358c86f3fb300ebada0aaead9cd978616640bdce62f0f947ab7cd354fb1ec223bff5f.83ac29f37d94588bf486c3656023249dc24daa583dfbaa701f35cea94b0358c86f3fb300ebada0aaead9cd978616640bdce62f0f947ab7cd354fb1ec223bff5f.png: file name too long
ERROR Rebuild failed: open /Users/james/code/github/jloh/blog/public/posts/installing-newrelic-monitor-gitlab/newrelic_install_menu.8c9fc81716df711510656edd5b972e5938bc81ef59a7cc84c6cdd2a9876a7eb09d47c02f6edd82b70b9d633e4e29f02d2bdb0feeeed9a8d315a104daaa770004.8c9fc81716df711510656edd5b972e5938bc81ef59a7cc84c6cdd2a9876a7eb09d47c02f6edd82b70b9d633e4e29f02d2bdb0feeeed9a8d315a104daaa770004.png: file name too long
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 475 ms

Note that the images have the fingerprint once, a ., then the same fingerprint again.

I use a render-image.html hook that looks like this:

{{- with .Page.Resources.GetMatch .Destination -}}
	{{- $image := . -}}
	{{- $imageSHA := . | resources.Fingerprint "sha512" -}}
	{{- $src := $image.RelPermalink -}}

	{{- if $src -}}
		{{- $srcSets := slice -}}
		{{- range $imageSize := sort (site.Params.photoWidths) -}}
			{{- if ge $image.Width . }}
				{{- $srcSets = $srcSets | append (print (($image.Resize (print $imageSize "x")).RelPermalink | safeURL ) " " $imageSize "w") -}}
			{{- end -}}
		{{- end -}}
		{{- $srcSets = $srcSets | append (print (print ($imageSHA.RelPermalink) " " $image.Width "w")) -}}
		{{- $srcSets = delimit $srcSets ", " | safeHTMLAttr -}}
		<img
			class="mx-auto my-6"
			sizes="(min-width: 42rem) 42rem, 100vw"
			{{ printf "srcset=%q" $srcSets | safeHTMLAttr }}
			src="{{ $imageSHA.RelPermalink }}"
			alt="{{ $.Text }}"
			{{ with $.Title }}title="{{ . }}"{{ end }}
			width="{{ $image.Width }}"
			height="{{ $image.Height }}"
			loading="lazy"
		/>
	{{- else -}}
		{{- errorf "failed to find image" -}}
		could not find image
	{{- end -}}
{{- else -}}

	{{- if strings.HasPrefix .Destination "http" -}}
		<img
			loading="lazy"
			class="mx-auto my-6"
			src="{{ .Destination | safeURL }}"
			alt="{{ .Text }}"
			{{ with .Title }}title="{{ . }}"{{ end }}
		/>
	{{- else -}}
		<img
			loading="lazy"
			class="mx-auto my-6"
			src="{{ .Destination | safeURL }}"
			alt="{{ .Text }}"
			{{ with .Title }}title="{{ . }}"{{ end }}
			{{ with imageConfig ( printf "static/%s" .Destination ) }}width="{{ .Width }}" height="{{ .Height }}"{{ end }}
		/>
	{{- end -}}
{{- end -}}

I'm having trouble getting a reliable replication case, it seems to happen randomly. I wasn't editing the post that has those images either, it was a different post.

As per #12655 I am using the new templates.Defer functionality, I don't know whether thats involved. Apologies if this is a problem with my template but I have only been experiencing this recently!

@bep bep added this to the v0.130.0 milestone Jul 22, 2024
@bep bep removed the NeedsTriage label Jul 22, 2024
@bep bep modified the milestones: v0.130.0, v0.131.0 Jul 30, 2024
@bep bep self-assigned this Jul 31, 2024
bep added a commit to bep/hugo that referenced this issue Jul 31, 2024
bep added a commit to bep/hugo that referenced this issue Jul 31, 2024
@bep bep closed this as completed in 216a69a Jul 31, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants