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

Permission denied to %temp% on Windows #1

Closed
spanznet opened this issue May 27, 2024 · 3 comments
Closed

Permission denied to %temp% on Windows #1

spanznet opened this issue May 27, 2024 · 3 comments

Comments

@spanznet
Copy link

Hi,

Thank you for this, it's incredibly handy and time saving!

One issue I had on Windows11 is the below:

           INFO     Saving modified data to "C:\Users\<user>\AppData\Local\Temp\tmpa57mytmc"                garmin.py:107
Traceback (most recent call last):
  File "C:\Users\<user>\OneDrive\Documents\indieVelo\A7B580193A86E911\FITFiles\garmin.py", line 215, in <module>
    upload_all()
  File "C:\Users\<user>\OneDrive\Documents\indieVelo\A7B580193A86E911\FITFiles\garmin.py", line 180, in upload_all
    output = edit_fit(Path(f), output=Path(fp.name))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\<user>\OneDrive\Documents\indieVelo\A7B580193A86E911\FITFiles\garmin.py", line 108, in edit_fit
    modified_file.to_file(str(output))
  File "C:\Users\<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\fit_tool\fit_file.py", line 156, in to_file
    with open(path, 'wb') as file_object:
         ^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\<user>\\AppData\\Local\\Temp\\tmpa57mytmc'

But after a quick google I was able to get it to work by adding delete=False to line 179

with NamedTemporaryFile(delete=False) as fp:
@jat255
Copy link
Owner

jat255 commented May 28, 2024

Hmm, hadn't seen this as I use Linux, so thanks for pointing it out. It looks like this is the ultimate issue:

bravoserver/bravo#111 (comment):

It's an issue with Python, but it's not a bug. They clearly document this in the docs:

Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later). http://docs.python.org/library/tempfile.html#tempfile.NamedTemporaryFile

It's good delete=False fixes the issue, but I don't love that as a solution since it will lead to a lot of leftover "temporary" files. Can you try with with NamedTemporaryFile(delete=True, delete_on_close=False) as fp: to see if that fixes it? If I understand correctly, that will allow for the file to get deleted when the context manager exits, but still allow Windows to do what it needs to to access the file?

@spanznet
Copy link
Author

Yes, that also works, and no tmp file leftover.

@jat255 jat255 closed this as completed in b3ae2cf May 29, 2024
@jat255
Copy link
Owner

jat255 commented May 29, 2024

Awesome, thanks for confirming. It works on my end in Linux, so I just added that into the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants