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.ismount sometimes raises FileNotFoundError on Windows #73045

Open
lazka mannequin opened this issue Dec 2, 2016 · 11 comments
Open

os.path.ismount sometimes raises FileNotFoundError on Windows #73045

lazka mannequin opened this issue Dec 2, 2016 · 11 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes easy OS-windows type-bug An unexpected behavior, bug, or error

Comments

@lazka
Copy link
Mannequin

lazka mannequin commented Dec 2, 2016

BPO 28859
Nosy @pfmoore, @tjguk, @zware, @zooba, @wm75, @lazka, @csabella, @dan1994, @szb512, @digglife, @AkechiShiro, @ankeshsaha
PRs
  • bpo-28859: Fix return value of ismount on Windows #19109
  • 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 = None
    created_at = <Date 2016-12-02.14:39:20.125>
    labels = ['easy', 'type-bug', '3.8', '3.9', '3.7', 'OS-windows']
    title = 'os.path.ismount sometimes raises FileNotFoundError on Windows'
    updated_at = <Date 2020-05-23.20:05:59.911>
    user = 'https://github.com/lazka'

    bugs.python.org fields:

    activity = <Date 2020-05-23.20:05:59.911>
    actor = 'cheryl.sabella'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Windows']
    creation = <Date 2016-12-02.14:39:20.125>
    creator = 'lazka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 28859
    keywords = ['patch', 'easy', 'newcomer friendly']
    message_count = 11.0
    messages = ['282241', '357723', '361634', '362039', '362238', '364476', '364486', '365132', '365196', '365591', '369747']
    nosy_count = 13.0
    nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'steve.dower', 'wolma', 'lazka', 'cheryl.sabella', 'Dan Arad', 'scic0', 'sdcards', 'akarei', 'AkechiShiro', 'ankeshsaha']
    pr_nums = ['19109']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28859'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @lazka
    Copy link
    Mannequin Author

    lazka mannequin commented Dec 2, 2016

    It returns True for drives which don't exist and raises for paths starting with drives which don't exist.

    >>> os.path.exists("C:\\")
    True
    >>> os.path.ismount("C:\\")
    True
    >>> os.path.ismount("C:\\doesnotexist")
    False
    >>> os.path.exists("F:\\")
    False
    >>> os.path.ismount("F:\\")
    True
    >>> os.path.ismount("F:\\doesnotexist")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Users\lazka\AppData\Local\Programs\Python\Python35\lib\ntpath.py", line 290, in ismount
        return path.rstrip(seps) == _getvolumepathname(path).rstrip(seps)
    FileNotFoundError: [WinError 2] The system cannot find the file specified: 'F:\\doesnotexist'

    @lazka lazka mannequin added the OS-windows label Dec 2, 2016
    @vadmium vadmium changed the title os.path.mount sometimes raises FileNotFoundError on Windows os.path.ismount sometimes raises FileNotFoundError on Windows Dec 2, 2016
    @lazka lazka mannequin added the 3.7 (EOL) end of life label Mar 20, 2019
    @zooba
    Copy link
    Member

    zooba commented Dec 2, 2019

    Traditionally we handle exceptions in os.path.is* functions and return False.

    @zooba zooba added easy 3.8 only security fixes 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels Dec 2, 2019
    @scic0
    Copy link
    Mannequin

    scic0 mannequin commented Feb 8, 2020

    I would like to take this issue as my first issue to start contributing to Python development.

    @szb512
    Copy link
    Mannequin

    szb512 mannequin commented Feb 16, 2020

    I am going to think maybe it was the "os.path.ismount" command that is causing the issue. Does the file exist?

    @zooba
    Copy link
    Member

    zooba commented Feb 18, 2020

    I am going to think maybe it was the "os.path.ismount" command that is causing the issue. Does the file exist?

    If the file does not exist, it is definitely not a mount point. So the function should return False instead of raising an error.

    @AkechiShiro
    Copy link
    Mannequin

    AkechiShiro mannequin commented Mar 17, 2020

    Nishant Misra are you still working on this issue, if not could I take it from now on, as my first issue and contribution to Python?

    @scic0
    Copy link
    Mannequin

    scic0 mannequin commented Mar 17, 2020

    Yes Lahfa Samy, you can take it up. I did not work on the issue.

    @digglife
    Copy link
    Mannequin

    digglife mannequin commented Mar 27, 2020

    I submitted a PR and get reviewed by @lazka. Is there anything I should do for pushing it to next step?

    @zooba
    Copy link
    Member

    zooba commented Mar 27, 2020

    Reminding us on here is helpful (for me, anyway).

    I just left a couple of suggestions to make sure we handle all the cases.

    It's important when you change or add tests that you make sure the test fails without your fix - otherwise it might not be testing the fix!

    @ankeshsaha
    Copy link
    Mannequin

    ankeshsaha mannequin commented Apr 2, 2020

    s I have tried to workout a solution for the problem. Below is my observation and possible solution.

    os.path.ismount("F:\\doesnotexist")

    Exception occurs for the above line if the system fails to find both drive and the path that follows it.

    A 'FileNotFoundError' exception is thrown. If we can handle this exception and return false for method ismount(), then problem can be resolved.

    I changed the existing code ismount method and it is working.
    Existing code=>
    if _getvolumepathname:
    return path.rstrip(seps) == _getvolumepathname(path).rstrip(seps)
    else:
    return False

    Changed Code=>
    if _getvolumepathname:
    try:
    return path.rstrip(seps) == _getvolumepathname(path).rstrip(seps)
    except FileNotFoundError:
    return False

    Please check, if this solution is correct.

    @csabella
    Copy link
    Contributor

    @steve.dower, please review the changes when you get a chance. Thanks!

    @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
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes easy OS-windows type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants