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

os.path.normcase documentation/behaviour unclear on Mac OS X #47735

Closed
ijmorlan mannequin opened this issue Aug 1, 2008 · 13 comments
Closed

os.path.normcase documentation/behaviour unclear on Mac OS X #47735

ijmorlan mannequin opened this issue Aug 1, 2008 · 13 comments
Labels
OS-mac type-bug An unexpected behavior, bug, or error

Comments

@ijmorlan
Copy link
Mannequin

ijmorlan mannequin commented Aug 1, 2008

BPO 3485
Nosy @loewis, @ronaldoussoren, @ned-deily, @ezio-melotti
Files
  • normcase.patch
  • 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 = None
    closed_at = <Date 2014-06-18.20:12:35.074>
    created_at = <Date 2008-08-01.17:16:04.916>
    labels = ['OS-mac', 'type-bug']
    title = 'os.path.normcase documentation/behaviour unclear on Mac OS X'
    updated_at = <Date 2014-06-18.20:12:35.073>
    user = 'https://bugs.python.org/ijmorlan'

    bugs.python.org fields:

    activity = <Date 2014-06-18.20:12:35.073>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-06-18.20:12:35.074>
    closer = 'ned.deily'
    components = ['macOS']
    creation = <Date 2008-08-01.17:16:04.916>
    creator = 'ijmorlan'
    dependencies = []
    files = ['13469']
    hgrepos = []
    issue_num = 3485
    keywords = ['patch']
    message_count = 13.0
    messages = ['70571', '70584', '70586', '70599', '84549', '84631', '108607', '108794', '108804', '109470', '220949', '220950', '220951']
    nosy_count = 8.0
    nosy_names = ['loewis', 'ronaldoussoren', 'ijmorlan', 'ned.deily', 'ezio.melotti', 'matthieu.labbe', 'BreamoreBoy', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue3485'
    versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']

    @ijmorlan
    Copy link
    Mannequin Author

    ijmorlan mannequin commented Aug 1, 2008

    $ python
    Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) 
    [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from os.path import normcase
    >>> normcase ('aB')
    'aB'
    >>>

    From http://docs.python.org/lib/module-os.path.html: "On Unix, this
    returns the path unchanged; on case-insensitive filesystems, it converts
    the path to lowercase." Of course, Mac OS X is both Unix and
    case-insensitive, which is a rather bizarre combination, but that's it
    is. Where is the item for "make all file systems case-sensitive, put
    the case-insensitivity in the user interface"?

    @ijmorlan ijmorlan mannequin added OS-mac type-bug An unexpected behavior, bug, or error labels Aug 1, 2008
    @ned-deily
    Copy link
    Member

    "Of course, Mac OS X is both Unix and case-insensitive"

    Not so. Case-{in|}sensitivity is an attribute of HFS+ file systems that is
    specifiable when a file system is created; it's true that the default is
    still case-insensitive. There are also other case-sensitive file systems
    supported on OS X.

    @ijmorlan
    Copy link
    Mannequin Author

    ijmorlan mannequin commented Aug 1, 2008

    Ok, good point. Perhaps the documentation should be updated to clarify
    that Mac OS is treated as Unix even though a default Mac OS X
    installation will have a case-insensitive file system. Wouldn't it be
    possible for a Windows machine to have a case-sensitive file system
    similarly? Or is it more "built-in" that the file system on a Windows
    box will be case-insensitive?

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Aug 1, 2008

    On Windows, case-insensitivity is part of the API, not of the file
    system. NTFS itself is case-sensitive, and there are case-sensitive
    subsystems on top of it (e.g. the POSIX subsystem, Interix). Win32, when
    calling the file system, asks for case-insensitive lookup (which NTFS
    also supports efficiently).

    I believe FAT is inherently case-insensitive.

    @ronaldoussoren
    Copy link
    Contributor

    The following patch explicitly mentions that os.path.normcase treats OSX
    like any other Unix platform.

    I'm in favor of applying this.

    @ronaldoussoren
    Copy link
    Contributor

    I've committed a fix for this in r70746 and ported this to 3.1 and 2.6 as
    well.

    @ezio-melotti
    Copy link
    Member

    I'm reopening this because now the normcase implementation of posixpath has a todo that says "on Mac OS X, this should really return s.lower()." (see r66743).
    There is some discussion about this in bpo-9018.

    @ezio-melotti ezio-melotti reopened this Jun 25, 2010
    @ronaldoussoren
    Copy link
    Contributor

    The comment is wrong, os.path.normcase should not return s.lower(), as the other issue notes the case sensitivity is filesystem dependent.

    Returning s.lower() will break code when dealing with paths that refer to an NFS share on a Linux server, or to a path on a local case sensitive file system.

    IMHO The comment in posixpath should be changed to something like this:

    # On MacOS X most but not all filesystems are case sensitive, which
    # means that using normcase(p1) != normcase(p2) doesn't necessarily mean
    # that the paths refer to different files.

    The current comment gives the impression that a trivial should be applied, which isn't true.

    @ezio-melotti
    Copy link
    Member

    Changing the function is better than changing the comment.
    Although changing just the comment is better than leaving it unchanged.

    @ronaldoussoren
    Copy link
    Contributor

    Note that this does not just affect MacOSX, this even affects Linux (although the behaviour on the default filesystems is different).

    On Linux the default is case-sensitive filesystems, but you can use network filesystems that have case-insensitive behavior, for example by using a CIFS share.

    This means that /mnt/myserver-share/foo/bar and /mnt/myserver-share/FOO/BAR may or may not refer to the same "object": there aren't the same if /mnt/myserver-share is a regular Linux filesystem but will be when /mnt/myserver-share is a mount from a CIFS server.

    In short: os.path.normcase is hopelessly naive in its assumptions about system behavior.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jun 18, 2014

    Is this or could this be addressed via the new pathlib module?

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 18, 2014

    New changeset a854d23305de by Ned Deily in branch '3.4':
    Issue bpo-3485: remove misleading comment
    http://hg.python.org/cpython/rev/a854d23305de

    New changeset 3edda677119e by Ned Deily in branch 'default':
    Issue bpo-3485: merge from 3.4
    http://hg.python.org/cpython/rev/3edda677119e

    @ned-deily
    Copy link
    Member

    The misleading "TODO" comment has been removed.

    @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-mac type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants