[Python-bugs-list] [ python-Bugs-591104 ] os.tmpfile() can fail on win32

noreply@sourceforge.net noreply@sourceforge.net
Tue, 06 Aug 2002 07:40:38 -0700


Bugs item #591104, was opened at 2002-08-05 14:23
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=591104&group_id=5470

Category: Windows
Group: Python 2.2.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Joseph Barillari (jdbarillari)
Assigned to: Mark Hammond (mhammond)
Summary: os.tmpfile() can fail on win32

Initial Comment:
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

----------------------------------------------------------------------

>Comment By: Joseph Barillari (jdbarillari)
Date: 2002-08-06 14:40

Message:
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
>>>

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-08-06 03:19

Message:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=591104&group_id=5470