2

I am creating a small utility that can be used to download and install updates for games that don't run through storefronts that automate the process. For the most part, it's been working perfectly!

As part of the testing, we've discovered that hidden files seem to confound the extraction process. It consistently results in this error:

PermissionError: [Errno 13] Permission denied: 'E:\path\hidden.txt'

I wasn't able to find much in the way of hidden files and Python interacting, but I did find this old question noting that Python itself is unable to handle hidden files in "standard" modes (like r, w, etc) due to how the underlying Win32 API is used. I tried using a similar solution for my code but had no luck. I dug a bit into the zipfile module itself to see what I could find and noticed this:

mode: The mode can be either read 'r', write 'w', exclusive create 'x', or append 'a'.

Am I right in thinking that this means there's no way to proceed from here using the zipfile module? In any case, any suggestions on how to proceed are certainly welcome!

The relevant sections of code I'm using is as follows:

updateFile = zipfile.ZipFile(updateTarget, 'r')
        updateFile.extractall()
        updateFile.close()

Using this as is results in a PermissionError. I've also tried the other three available modes. Ideally, the unzip process would proceed as normally and overwrite the hidden files.

Edit 1: Running as administrator has no effect on the process.

Edit 2: A bit more experimenting revealed that as long as the original file (the one to be overwritten) is not hidden, the extraction proceeds smoothly, though the resultant file will not be hidden (even though the downloaded archive's version of the file is set to hidden).

Edit 3: Per Thomas' suggestion in the comments, I looked into it using Process Monitor which I have no experience with so. I have no clue what I'm looking at really other than the process failed. See screenshot below:

Screenshot of failed process details from Process Monitor.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • Does this answer your question? [Python 3.6.1 - PermissionError: \[Errno 13\] Permission denied shown when trying to unzip a file](https://stackoverflow.com/questions/44185662/python-3-6-1-permissionerror-errno-13-permission-denied-shown-when-trying-t) – Abhigyan Mar 22 '22 at 11:20
  • Hi @Abhigyan, good catch on trying that, but no! Running as admin has had no effect on it. – AiedailEclipsed Mar 22 '22 at 11:25
  • What are the NTFS permissions on the file? Who owns it etc.? Even an admin can remove himself from the list. Also: if the file is in exclusive use, it may block any operations. – Thomas Weller Mar 22 '22 at 11:29
  • Odd that running the program as admin did not have an effect. Might be some underlying system controls that causes the access error to be thrown. You may need to step the app through a debugger and see where exactly it is failing and see if you are able to update, or modify any policies or restrictions that getting in your way. Could even be as simple as AV software or Windows Defender, not that I recommend turning it off. – Lukas Nelson Mar 22 '22 at 11:42
  • @ThomasWeller I am the file owner, with an admin account on my computer. I have full control over the file, except for the "special permissions" ability. And no, the file isn't in use by any other program. That was my first thought as well when I heard the report. – AiedailEclipsed Mar 22 '22 at 11:46
  • @LukasNelson I've already done that and it is failing precisely at the extraction process. The post I referenced in my OP seems to indicate it is a shortcoming on the way Python as a whole interacts with the Win32 API. – AiedailEclipsed Mar 22 '22 at 11:52
  • Have you tried diagnosing the problem with Process Monitor? – Thomas Weller Mar 22 '22 at 15:39
  • @ThomasWeller never heard of it! I'll definitely take a look though, any recommendations on places to start? – AiedailEclipsed Mar 22 '22 at 16:10

0 Answers0