[issue37834] readlink on Windows cannot read app exec links

Steve Dower report at bugs.python.org
Thu Aug 15 17:28:20 EDT 2019


Steve Dower <steve.dower at python.org> added the comment:

> So we _do_ want to "upgrade" lstat() to stat() when it's not a symlink.

Except this bug came about because we want to _downgrade_ stat() to lstat() when it's an appexeclink, because the whole point of those is to use them without following them (and yeah, most operations are going to fail, but they'd fail against the target file too).

So we have this logic:

def xstat(path, traverse):
    f = open(path, flags | (0 if traverse else OPEN_REPARSE_POINT))
    if !f:
        # Special case for appexeclink
        if traverse and ERROR_CANT_OPEN_FILE:
            st = xstat(path, !traverse)
            if st.reparse_tag == APPEXECLINC:
                return st
            raise ERROR_CANT_OPEN_FILE
        # Handle "likely" errors
        if ERROR_ACCESS_DENIED or SHARING_VIOLATION:
            st = read_from_dir(os.path.split(path))
    else:
        st = read_from_file(f)

    # Always make the OS resolve "unknown" reparse points
    ALLOWED_TO_TRAVERSE = {SYMLINK, MOUNT_POINT}
    if !traverse and st.reparse_tag not in ALLOWED_TO_TRAVERSE:
        return xstat(path, !traverse)

    return st

And the open question is just whether MOUNT_POINT should be in that set near the end. I believe it should, since the alternative is to force all Python developers to write special Windows-only code to handle directory junctions.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37834>
_______________________________________


More information about the Python-bugs-list mailing list