dolthub / doltpy

A Python API for Dolt
Apache License 2.0
55 stars 13 forks source link

PermissionError: [Errno 13] Permission denied on Windows when writing to temp file #155

Open geertdepuydt opened 3 years ago

geertdepuydt commented 3 years ago

On windows whener the library wants to create and write to a new temp file a PermissionError is raised.

For example just asking for the dolt.active_branch will crash on windows:

Traceback (most recent call last): File "C:\dev\al\al-webtools\scripts\life_sciences_companies_dataset.py", line 288, in <module> main() File "C:\dev\al\al-webtools\scripts\life_sciences_companies_dataset.py", line 246, in main print(dolt.active_branch) File "C:\dev\al\al-webtools\venv\lib\site-packages\doltcli\dolt.py", line 301, in active_branch active_branch = self.sql(f"select active_branch() as a", result_format="csv")[ File "C:\dev\al\al-webtools\venv\lib\site-packages\doltcli\dolt.py", line 610, in sql output_file = self.execute(args, stdout_to_file=f.name, **kwargs) File "C:\dev\al\al-webtools\venv\lib\site-packages\doltcli\dolt.py", line 332, in execute output = _execute(args, self.repo_dir, outfile=stdout_to_file) File "C:\dev\al\al-webtools\venv\lib\site-packages\doltcli\dolt.py", line 81, in _execute with open(outfile, "w") as f: PermissionError: [Errno 13] Permission denied: 'C:\\Users\\geert\\AppData\\Local\\Temp\\tmp58y5brjv'

I have tried changing my permissions to allow writing to files in this temp folder but still can't get it to work. Also runniung PyCharm as administrator, or even setting my python interpreter to run as administartor by default did not help.

I think this stack overflow thread describes the issue at hand on windows: https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file

Basically this (Python docs): tempfile.NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, delete=True, *, errors=None) This function operates exactly as TemporaryFile() does, except that the file is guaranteed to have a visible name in the file system (on Unix, the directory entry is not unlinked). That name can be retrieved from the name attribute of the returned file-like object. 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).