Title: os.path.isdir does not recognize symlinks in z/OS
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.7
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.

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

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'))
$print (os.path.exists('/tmp'))
$print (os.path.isfile('/tmp'))
$print (os.path.islink('/tmp'))
msg11409 (view) Author: Jim Baker (zyasoft) Date: 2017-05-27.18:04:28
isdir is implemented in Lib/ with the following code:

def isdir(s):
    """Return true if the pathname refers to an existing directory."""
        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):

Perhaps Z/OS does not support "unix:*" attributes, or only does so partially. We do know that Java does support, and in general the Java implementation will always be more reliable than using other predicates, *if available*.

So that is my recommendation: customize usage to use Java where possible, possibly by some specific Jython extensions in
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.
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