Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement stat.st_dev and os.path.samefile on windows #56148

Closed
amauryfa opened this issue Apr 27, 2011 · 20 comments
Closed

Implement stat.st_dev and os.path.samefile on windows #56148

amauryfa opened this issue Apr 27, 2011 · 20 comments
Assignees
Labels
OS-windows type-feature A feature request or enhancement

Comments

@amauryfa
Copy link
Member

BPO 11939
Nosy @amauryfa, @briancurtin, @serhiy-storchaka
Files
  • issue11939.diff
  • issue11939_v2.diff
  • issue11939_v3.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/briancurtin'
    closed_at = <Date 2012-12-26.13:12:24.228>
    created_at = <Date 2011-04-27.16:59:42.339>
    labels = ['type-feature', 'OS-windows']
    title = 'Implement stat.st_dev and os.path.samefile on windows'
    updated_at = <Date 2013-01-01.18:32:19.605>
    user = 'https://github.com/amauryfa'

    bugs.python.org fields:

    activity = <Date 2013-01-01.18:32:19.605>
    actor = 'brian.curtin'
    assignee = 'brian.curtin'
    closed = True
    closed_date = <Date 2012-12-26.13:12:24.228>
    closer = 'brian.curtin'
    components = ['Windows']
    creation = <Date 2011-04-27.16:59:42.339>
    creator = 'amaury.forgeotdarc'
    dependencies = []
    files = ['28423', '28429', '28430']
    hgrepos = []
    issue_num = 11939
    keywords = ['patch', 'needs review']
    message_count = 20.0
    messages = ['134595', '134602', '178090', '178101', '178102', '178103', '178104', '178105', '178108', '178206', '178207', '178208', '178211', '178218', '178220', '178712', '178727', '178739', '178740', '178742']
    nosy_count = 4.0
    nosy_names = ['amaury.forgeotdarc', 'brian.curtin', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue11939'
    versions = ['Python 3.4']

    @amauryfa
    Copy link
    Member Author

    Since 9cd1036455e7, os.stat() on Windows fills the st_ino member;
    it could fill st_dev just as easily;
    then os.path.samefile() could be shared with the posix implementation.

    @amauryfa amauryfa added OS-windows type-feature A feature request or enhancement labels Apr 27, 2011
    @briancurtin
    Copy link
    Member

    I created/assigned bpo-10646 to myself for other samefile issues - I can cover this as well unless someone beats me to it.

    @briancurtin briancurtin self-assigned this Apr 27, 2011
    @briancurtin
    Copy link
    Member

    Here's a patch that fills st_dev, and while we're at it st_rdev (which is the same value).

    I've moved the implementation of samefile/sameopenfile/samestat from Lib/posixpath.py over to Lib/genericpath.py and then removed the implementation from Lib/ntpath.py, so those functions are now common. The same goes for tests - I've rearranged tests towards test_genericpath. I also removed _getfileinformation from Modules/posixmodule.c because it's no longer being used.

    @serhiy-storchaka
    Copy link
    Member

    What about macpath? I think test_macpath will fail.

    @briancurtin
    Copy link
    Member

    Why do you think that? I don't have a mac so I can't test it.

    @briancurtin
    Copy link
    Member

    Here is an updated patch addressing the sameopenfile that remained in Lib/ntpath.py, thanks to Sehriy's comment on the review.

    @serhiy-storchaka
    Copy link
    Member

    Hmm. test_macpath will now run the tests for samefile etc. macpath doesn't contain os.path.samefile. But in Modules/posixmodule.c I don't see any special cases for classic MacOS. Actually, I don't know how tests behave on classic MacOS.

    Please update the documentation (availability, versionchanged).

    @serhiy-storchaka
    Copy link
    Member

    On other hand, you should add "samefile", "sameopenfile" and "samestat" back to __all__ in posixpath and ntpath. __all__ is a list of exported names, not a list of defined names.

    @briancurtin
    Copy link
    Member

    Docs and the __all__ changes in V3 patch.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 26, 2012

    New changeset 189b21f9bc0c by Brian Curtin in branch 'default':
    Fix bpo-11939. Set st_dev attribute on Windows to simplify os.path.samefile.
    http://hg.python.org/cpython/rev/189b21f9bc0c

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 26, 2012

    New changeset 82531b78b719 by Brian Curtin in branch 'default':
    Add NEWS entry for fixing bpo-11939
    http://hg.python.org/cpython/rev/82531b78b719

    @briancurtin
    Copy link
    Member

    Thanks for the reviews.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 26, 2012

    New changeset 9e980454b85e by Brian Curtin in branch 'default':
    Add tests for Issue bpo-10646.
    http://hg.python.org/cpython/rev/9e980454b85e

    @serhiy-storchaka
    Copy link
    Member

    Try on Windows:

    >>> import os
    >>> from os.path import *
    >>> samestat(os.stat('.'), os.stat('.'))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'samestat' is not defined

    @briancurtin
    Copy link
    Member

    Separate issue. Fixed in bpo-16788.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 31, 2012

    New changeset 3738d270c54a by Brian Curtin in branch 'default':
    st_dev/st_rdev should be unsigned long as dwVolumeSerialNumber, which it is set to, is a DWORD. This was fixed in bpo-11939 and the overflow was mentioned in bpo-10657 and seen by me on some machines.
    http://hg.python.org/cpython/rev/3738d270c54a

    @serhiy-storchaka
    Copy link
    Member

    New changeset 3738d270c54a by Brian Curtin in branch 'default':
    st_dev/st_rdev should be unsigned long as dwVolumeSerialNumber, which it is
    set to, is a DWORD. This was fixed in bpo-11939 and the overflow was
    mentioned in bpo-10657 and seen by me on some machines.
    http://hg.python.org/cpython/rev/3738d270c54a

    But than st_dev used as long in _pystat_fromstructstat(). Perhaps you should
    check if st_dev is negative and then select
    PyLong_FromLong/PyLong_FromLongLong or
    PyLong_FromUnsignedLong/PyLong_FromUnsignedLongLong.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 1, 2013

    New changeset 61bada808b34 by Brian Curtin in branch 'default':
    Set st_dev on Windows as unsigned long to match its DWORD type, related to the change to fix bpo-11939.
    http://hg.python.org/cpython/rev/61bada808b34

    @serhiy-storchaka
    Copy link
    Member

    Now the code is wrong on non-Windows without PY_LONG_LONG and with signed st_dev.

    @briancurtin
    Copy link
    Member

    Backed out the changeset. If you have a solution, feel free to fix it.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    OS-windows type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants