Windows Permissions Error copying static files

Background: I’m on Windows 10.

I tried embedding an image in one of my posts. It went well in hugo server mode. When I compiled the site with the hugo command:

Start building sites …
Total in 3287 ms
Error: Error copying static files: open 
C:\path\to\myblog\public\static\the_image.png: Access is denied.

I am using the static/static trick described here. This works perfectly fine in hugo server mode, as my image shows up.

Yes, I have the extended version of Hugo installed. Yes, I tried the downgrading trick I did last time this happened. No, I cannot downgrade infinitely, since v0.79.0 is unsafe (and that’s an unsustainable bodge anyway). No, I cannot share the code repository.

How do I finally solve this issue? Like, a real solution.

How so? Please do elaborate.

I just remembered you are referring to the 0.79.1 Release Notes.

Windows users who ran hugo inside untrusted Hugo sites were affected.

Normally, you shouldn’t really be affected by the above.

Fair enough. However, you can create a sample repository with dummy content, that reproduces the issue and share it for us to see what is going on.

We cannot know what is the issue you are referring to, if we cannot reproduce it.

I am on Windows 10 and I have never encountered anything of the sort you are describing in this topic.

v0.79.0 (and lower(?)) had some kind of security vulnerability. I’m not sure if I’d be affected, since I don’t run untrusted Hugo sites.

Good idea on the repository! Here is a dummy version of my code. It reproduces the error on my system.

I believe the problem has to do with Windows’ permissions/admin weirdness. But none of the googled answers work in my situation. They’re either solving a different version of the problem (like the permissions being on a server, rather than the desktop), or they suggest fixes that, themselves, don’t work (like changing a windows permission, which mysteriously undoes itself).

The project builds fine on my end.

$ hugo
Start building sites …

                   | EN
  Pages            | 16
  Paginator pages  |  0
  Non-page files   |  0
  Static files     |  1
  Processed images |  0
  Aliases          |  3
  Sitemaps         |  0
  Cleaned          |  0

Total in 459 ms

As you suspected the problem appears to be due to your local Windows setup.
Perhaps someone has encountered the situation you describe and can offer a tip.

The access to create or write in the folder public is denied, NOT to the image. That means, that you have no folder public created AND Hugo is missing rights to create files in your directory. The quickest way is probably to create a folder named public and add a file .gitignore inside of that folder with the following content:


In the end:

etc. etc.

Then add .gitignore to your repo and the problem will probably disappear. If not, then it’s the next level static folder that can’t be created.

For the folder rights on yourdirectory you might need to ask in a windows forum. Probably right click, settings, security and create rights (read/write) for the user that Hugo is running under. That might be your user, that might be another one if it’s somehow installed globally or linked from another user - we don’t know, because you don’t tell :slight_smile:

1 Like

I don’t think the gitignore is the problem, since my actual code is not a real repo.

Thank you for the tip though! And I will ask on a windows forum and report back if something there works.

(For the record, I tried my old version-downgrading trick down to v0.78.1, no success.)

Does your project reside under the Onedrive or Dropbox folder?

Nope, It’s in a normal file directory on Win10.

It’s not, but it would have kept the public folder existing on a repository-based site. You need to get the file rights working on your station. Sometimes if you copy from one Windows computer to another the ownership on the new computer does not work, because although you might have the same name the ID of the user is different. So right click on the main folder (where the website is in) and check the tab security. Hugo needs to be able to create/write files recursively.

All users (including SYSTEM) that can be selected, already have all permissions on my site’s folder (the top-level one containing archetypes, content, data, layouts…). Except “special permissions”, which seems to just be more specific permission definitions anyway (so it wouldn’t need to be checked to give full perms).

Is Hugo some other “user” in the system? Typing “Hugo” into the add user thing didn’t work. How do I give Hugo the permissions it needs?

Another bizarre thing:
The error is
Error: Error copying static files: open C:\.......\site_folder\public\static\my_image.png: Access is denied.

When I check the public\ folder created so far, it has the static\ folder, but the image is not in there.

So either the error is “It can’t copy the image to that folder.”, OR it might be “It thought it copied the image but didn’t.”. Unlikely, but wanted to point that out.

Another thing I just tried (that does NOT work):
Changing the name of the innermost static folder, to mysite_static.

I got the same “copying static files” error. (Even while running hugo command in Administrator command prompt.)

We cannot help you with your issue as it is a Windows permissions error that applies to your local machine.

We cannot reproduce the issue and we did not have similar reports about Windows permissions and the latest Hugo releases…

Please use an appropriate channel for Windows support.

Hint: searching for “windows access denied” wields several results in a search engine.

I am archiving the topic as it is not really related to Hugo.

This is a forum for Hugo support. We help with installation but we cannot help with OS specific issues like the one you described in your posts above.

Thank you for your understanding.