Issue2595

classification
Title: os.path.isdir does not recognize symlinks in z/OS
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.7
Milestone:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jeff.allen, trickyturtle, zyasoft
Priority: Keywords:

Created on 2017-05-26.14:38:38 by trickyturtle, last changed 2018-03-01.07:02:27 by jeff.allen.

Messages
msg11406 (view) Author: David Alexander (trickyturtle) Date: 2017-05-26.14:41:52
to test:
$import os 
$print (os.path.isdir('/tmp')) 
False 
$print (os.path.exists('/tmp')) 
True 
$print (os.path.isfile('/tmp')) 
False 
$print (os.path.islink('/tmp')) 
False 

symlink detection works correctly in jython 2.1
msg11407 (view) Author: David Alexander (trickyturtle) Date: 2017-05-26.15:04:50
in the example /tmp is a symlink, but a different symlink could be created using 'ln'

also, for reference, in 2.1 the above code would result in the following:
$print (os.path.isdir('/tmp'))
1
$print (os.path.exists('/tmp'))
1
$print (os.path.isfile('/tmp'))
0
$print (os.path.islink('/tmp'))
0
msg11409 (view) Author: Jim Baker (zyasoft) Date: 2017-05-27.18:04:28
isdir is implemented in Lib/genericpath.py with the following code:

def isdir(s):
    """Return true if the pathname refers to an existing directory."""
    try:
        st = os.stat(s)
    except os.error:
        return False
    return stat.S_ISDIR(st.st_mode)

In turn the core of the stat function is implemented here; Note that we have differentiated stat functions as well for file descriptors (fstat) and symbolic links (lstat), as well as for Windows (WindowsStatFunction):

https://github.com/jythontools/jython/blob/master/src/org/python/modules/posix/PosixModule.java#L1512

Perhaps Z/OS does not support "unix:*" attributes, or only does so partially. We do know that Java does support https://docs.oracle.com/javase/7/docs/api/java/io/File.html#isDirectory(), and in general the Java implementation will always be more reliable than using other predicates, *if available*.

So that is my recommendation: customize genericpath.py usage to use Java where possible, possibly by some specific Jython extensions in PosixModule.java.
msg11730 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-01.07:02:27
Picking up on original remark "symlink detection works correctly in jython 2.1", it's possible we broke this, but equally poossible the problem is with jnr.posix on which we depend.

Here and elsewhere in the os module it would be nice to depend only on Java's abstraction of the file system, if possible.
History
Date User Action Args
2018-03-01 07:02:27jeff.allensetnosy: + jeff.allen
messages: + msg11730
milestone: Jython 2.7.2 ->
2017-05-27 18:04:45zyasoftsetmilestone: Jython 2.7.0 -> Jython 2.7.2
2017-05-27 18:04:29zyasoftsetnosy: + zyasoft
messages: + msg11409
2017-05-26 15:07:01trickyturtlesettitle: os.path.isdir does not recognize symlinks in zOS -> os.path.isdir does not recognize symlinks in z/OS
2017-05-26 15:04:51trickyturtlesetmessages: + msg11407
2017-05-26 14:41:52trickyturtlesetmessages: + msg11406
2017-05-26 14:38:38trickyturtlecreate