Need help fixing an issue (possibly brief explanation of how hugofs works)

Hello and hope you’re doing well

I’m trying to fix this issue hugo server fails to refresh when filename includes NFC characters in MacOS · Issue #8429 · gohugoio/hugo · GitHub as my first contribution to Hugo.
I’ve spent some time on it today, and I was planning to spend more time in the upcoming days to figure things out. But if someone could explain things (even briefly) to me it’d be a huge boost.

I went back in time, and saw this code name = norm.NFC.String(name)
was added to fix this issue: Static sync to memory fails with Norwegian "å" · Issue #2203 · gohugoio/hugo · GitHub

I tested the issue, and it was happening on my device and it’s reproduced for me. Also if I comment the above code (which is now residing in fileinfo.go), the issue is fixed and livereload would work correctly.
I tried debugging code and to my wonder, the code is running both through the firstSite.processPartial and firstSite.process paths, but only livereload fails.

I have three questions that would help me better understand this.

  1. Here: Static sync to memory fails with Norwegian "å" · Issue #2203 · gohugoio/hugo · GitHub ks888 mentioned that “Mac OS’s HFS+ file system, a file name is automatically normalized to NFD. Even if we save a file name in NFC, we need to use NFD to open the file.”
    But I wonder why the code added to fix that is normalising names to NFC? Shouldn’t the fix actually be normalising to NFD on darwin architecture?

  2. I did not quite understand “fails to sync” in Static sync to memory fails with Norwegian "å" · Issue #2203 · gohugoio/hugo · GitHub what does it mean? I want to make sure whatever solution, will not break that one.

  3. How does hugofs work?
    Again ks888 mentioned this:
    “I think this issue can be fixed by normalizing a file name to NFC when files are added to Hugo’s filesystem, so that we can use NFC to access files in any cases.”
    but I don’t know how Hugo’s filesystem work. Any explanation or link to an explanation would help me.

I think I could figure things out eventually, but any help will help me a lot and is much appreciated!

I suspect the gist of that issue is that we normalize the filename when we read it:

if runtime.GOOS == "darwin" {
		// When a file system is HFS+, its filepath is in NFD form.
		return norm.NFC.String(filename)

And then when we get the change event we don’t find a match.

I guess that if you do the same on the incoming events, it should work.

1 Like

… but you could also just rename the file on disk :slight_smile:

Yeah it worked, I’ll send a PR tomorrow. Thanks!

Well, the actual point in selecting this issue was I wanted to get familiar with Hugo, and choose one that probably has the least side effect and also dependencies, is easy to reproduce, and is easy to test and probably fix.

And, well, having it fixed helps people not knowing why things are not working :wink:

1 Like