Issue1414

classification
Title: os.path.exists reports False incorrectly for UNC paths
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.7, Jython 2.5
process
Status: open Resolution: remind
Dependencies: Superseder:
Assigned To: Nosy List: crankycoder, fwierzbicki, zyasoft
Priority: normal Keywords:

Created on 2009-07-28.18:06:42 by crankycoder, last changed 2013-02-19.19:10:27 by fwierzbicki.

Messages
msg4956 (view) Author: Victor Ng (crankycoder) Date: 2009-07-28.18:06:41
os.path.exists returns False incorrectly for some UNC directories. I'm
not sure what the particular reasons are.  This is inconsistent with at
least CPython 2.5

For example in CPython 2.5.2:

>>> import os
>>> os.path.exists(u'\\\\cbmcc-fn-00020c\\1202\\RTMO')
True
>>> os.path.exists(u'\\\\cbmcc-fn-00020c\\1202\\RTMO\\')

Jython 2.5.0:

>>> import os
>>> os.path.exists(u'\\\\cbmcc-fn-00020c\\1202\\RTMO')
False
>>> os.path.exists(u'\\\\cbmcc-fn-00020c\\1202\\RTMO\\')
False

This is inconsitent even in Jython - sometimes, I get True, sometime
False.  For example - a different directory will report True for the
path without the trailing slash, but False for the path with the
trailing slash.
msg4957 (view) Author: Victor Ng (crankycoder) Date: 2009-07-28.18:07:28
This bug was detected on Jython 2.5.0 running on Windows XP
msg6078 (view) Author: Jim Baker (zyasoft) Date: 2010-09-20.19:10:08
Victor, do you have a repeatable unit test for this? Ideally we can build these UNC paths using tempfile, but I don't have the Windows background.
msg6094 (view) Author: Victor Ng (crankycoder) Date: 2010-09-23.18:27:54
This looks like a bug in the JRuby POSIX code.  I'll try to isolate the bug.
msg6104 (view) Author: Victor Ng (crankycoder) Date: 2010-09-28.16:00:48
This is a bug related to os.stat.  It might be related to msvcrt.dll's problems with the stat function.  I have no idea how it works on CPython, but it does work correctly.

A work around would be to implement os.path.exists using java.io.File instead.  This always seems to work.

Can we patch os.path.exists to just use java.io.File instead of trying to use stat()?

Here's the output using Jython 2.5.2beta2 and cpython 2.6 

----

> jython
Jython 2.5.2b2 (Release_2_5_2beta2:7124, Sep 14 2010, 00:11:45)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_20
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> path = '\\\\cbmcc-fn-00020c\\1202\RTMO'
>>> os.path.exists(path)
False
>>> os.stat(path)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 2] No such file or directory: '\\\\cbmcc-fn-00020c\\1202\\RTMO'
>>> import posix
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named posix
>>> from java.io import File
>>> File(path).exists()
True
>>> File(path).isDirectory()
True
>>>

[WMBCEXTRMW308GV]
Tue 09/28/2010 11:58:14.79
[D:\dev\sandbox\waffle]
> python
'python' is not recognized as an internal or external command,
operable program or batch file.

[WMBCEXTRMW308GV]
Tue 09/28/2010 11:58:16.82
[D:\dev\sandbox\waffle]
> c:\Python26\python.exe
Enthought Python Distribution -- http://www.enthought.com
Version: 6.1-1 (32-bit)

Python 2.6.4 |EPD 6.1-1 (32-bit)| (r264:75706, Nov 11 2009, 19:42:36) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> path = '\\\\cbmcc-fn-00020c\\1202\RTMO'
>>> os.path.exists(path)
True
>>> os.stat(path)
nt.stat_result(st_mode=16895, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1285689458L, st_
mtime=1285687451L, st_ctime=1214228226L)
>>>
msg6152 (view) Author: Victor Ng (crankycoder) Date: 2010-10-07.13:14:12
just to clarify - you can't reproduce this in a unit test with tempfile because you need an *actual* network file system.
msg7698 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-19.19:10:14
It would be nice to know if this is still a problem in 2.7 since we updated our jffi libs.
History
Date User Action Args
2013-02-19 19:10:27fwierzbickisetversions: + Jython 2.7
2013-02-19 19:10:14fwierzbickisetresolution: remind
messages: + msg7698
2013-02-19 19:09:40fwierzbickisetversions: + Jython 2.5, - 2.5.0
2010-10-07 13:14:12crankycodersetmessages: + msg6152
2010-09-28 16:01:00crankycodersetmessages: + msg6104
2010-09-23 18:27:55crankycodersetmessages: + msg6094
2010-09-20 19:10:08zyasoftsetpriority: high -> normal
nosy: + zyasoft
messages: + msg6078
2009-08-12 15:44:02fwierzbickisetnosy: + fwierzbicki
2009-07-29 05:37:18pjenveysetpriority: high
type: behaviour
2009-07-28 18:07:28crankycodersetmessages: + msg4957
2009-07-28 18:06:42crankycodercreate