This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.tmpfile() can fail on win32
Type: Stage:
Components: Windows Versions: Python 2.2
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: mhammond Nosy List: facundobatista, jdbarillari, mhammond, slyphon, tim.peters
Priority: normal Keywords:

Created on 2002-08-05 14:23 by jdbarillari, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (6)
msg11817 - (view) Author: Joseph Barillari (jdbarillari) Date: 2002-08-05 14:23
I've discovered what appears to be a bug in Python 2.2.1 
on Win32. I'm
using the 2.2.1 build that I downloaded from python.org. 
I'm running
Windows 2000.

If os.tmpfile() is exceuted when the CWD is a UNC path, 
the base of
which is not writeable by the current user, tmpfile will
fail. tempfile.TemporaryFile will work, so I suspect this is 
a bug in os.tmpfile().

For example:

C:\>pwd  
/cygdrive/c   #I use cygwin

C:\>bash    # I have to use bash; the DOS shell doesn't 
support UNC paths
bash: .bashrc: No such file or directory
bash-2.05a$ cd //bopp/jbarilla
bash-2.05a$ pwd
//bopp/jbarilla
bash-2.05a$ python
Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> import os; os.tmpfile()
<open file '<tmpfile>', mode 'w+' at 0x007762C0> # It 
works.
>>> ^Z

If I chmod 555 //bopp/jbarilla (from unix via NFS; 
incidentally,
"chmod 555 ." from cygwin is ineffectual), then tmpfile 
fails:

bash-2.05a$ pwd
//bopp/jbarilla
bash-2.05a$ python
Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> import os; os.tmpfile()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OSError: [Errno 13] Permission denied # Oops.

# However, tempfile.TemporaryFile works:

>>> import tempfile; tempfile.TemporaryFile()
<open file 'c:\DOCUME~1\jbarilla\LOCALS~1
\Temp\~1880-0', mode 'w+b' at 0x00779B00>

--Joe
msg11818 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-08-06 03:19
Logged In: YES 
user_id=31435

Assigned to Mark in case he has another idea, but I think 
you're out of luck.  os.tmpfile() does nothing except call 
Microsoft's tmpfile() function, and that doesn't allow 
specifying a directory.  If you don't have permission to 
create a file in the current directory, you lose, and Python's 
behavior here will change when Microsoft's does.

tempfile.TemporaryFile() "simulates" a temp file via other 
means, and can control which directory it uses.

BTW, do you really think this has something to do with UNC 
paths?  From what you said it seems to be a matter of 
having sufficient permission to scribble in the current 
directory.
msg11819 - (view) Author: Joseph Barillari (jdbarillari) Date: 2002-08-06 14:40
Logged In: YES 
user_id=589825

\quote{BTW, do you really think this has something to do 
with UNC 
paths?  From what you said it seems to be a matter of 
having sufficient permission to scribble in the current 
directory.}

Oops. You're right:

Z:\>touch a
touch: creating `a': Permission denied

Z:\>python
Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] 
on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> import os; os.tmpfile()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OSError: [Errno 13] Permission denied
>>>
msg11820 - (view) Author: Jonathan Simms (slyphon) Date: 2002-08-10 06:21
Logged In: YES 
user_id=404786

Hi, I'm a bit new here, but I'd like to help...

This like a cygwin issue. I've been using cygwin as a 
development environment for about a year, and nothing 
has driven me more crazy than the consistent problems 
converting between unc and win32 paths. There's the 
cygpath utility that you can put to use, it'll convert 
posix to win32 paths and vice-versa. Also, if you want 
to use chmod and unix-style permissions with cygwin, 
you need to make sure that the $CYGWIN variable has 
been set to include 'ntsec'.

related to the cygwin environment variable:
http://cygwin.com/cygwin-ug-net/using-cygwinenv.html


...This advice comes with no warranty, and I apologise 
if I'm mistakenly off-the-mark...

Cheers
--Jonathan
msg11821 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2004-12-01 02:13
Logged In: YES 
user_id=752496

Please, could you verify if this problem persists in Python 2.3.4
or 2.4?

If yes, in which version? Can you provide a test case?

If the problem is solved, from which version?

Note that if you fail to answer in one month, I'll close this bug
as "Won't fix".

Thank you! 

.    Facundo
msg11822 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2005-03-22 22:06
Logged In: YES 
user_id=752496

Deprecated. Reopen only if still happens in 2.3 or newer. 

.    Facundo
History
Date User Action Args
2022-04-10 16:05:33adminsetgithub: 36980
2002-08-05 14:23:25jdbarillaricreate