Issue 28859: os.path.ismount sometimes raises FileNotFoundError on Windows (original) (raw)

process

Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AkechiShiro, Dan Arad, akarei, ankeshsaha, cheryl.sabella, lazka, paul.moore, scic0, sdcards, steve.dower, tim.golden, wolma, zach.ware
Priority: normal Keywords: easy, newcomer friendly, patch

Created on 2016-12-02 14:39 by lazka, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 19109 closed akarei,2020-03-22 13:07
Messages (11)
msg282241 - (view) Author: Christoph Reiter (lazka) * Date: 2016-12-02 14:39
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 "", line 1, in 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'
msg357723 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-12-02 17:52
Traditionally we handle exceptions in os.path.is* functions and return False.
msg361634 - (view) Author: Nishant Misra (scic0) Date: 2020-02-08 15:34
I would like to take this issue as my first issue to start contributing to Python development.
msg362039 - (view) Author: szb512 (sdcards) Date: 2020-02-16 00:31
I am going to think maybe it was the "os.path.ismount" command that is causing the issue. Does the file exist?
msg362238 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-02-18 23:05
> 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.
msg364476 - (view) Author: Lahfa Samy (AkechiShiro) * Date: 2020-03-17 20:22
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?
msg364486 - (view) Author: Nishant Misra (scic0) Date: 2020-03-17 22:20
Yes Lahfa Samy, you can take it up. I did not work on the issue.
msg365132 - (view) Author: Zhu Sheng Li (akarei) * Date: 2020-03-27 02:58
I submitted a PR and get reviewed by @lazka. Is there anything I should do for pushing it to next step?
msg365196 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-03-27 23:56
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!
msg365591 - (view) Author: Ankesh Saha (ankeshsaha) * Date: 2020-04-02 13:07
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.
msg369747 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2020-05-23 20:05
@steve.dower, please review the changes when you get a chance. Thanks!
History
Date User Action Args
2022-04-11 14:58:40 admin set github: 73045
2020-05-23 20:05:59 cheryl.sabella set nosy: + cheryl.sabellamessages: +
2020-04-02 13:07:34 ankeshsaha set nosy: + ankeshsahamessages: +
2020-03-27 23:56:39 steve.dower set messages: +
2020-03-27 02:58:23 akarei set messages: +
2020-03-22 13:07:10 akarei set keywords: + patchnosy: + akareipull_requests: + <pull%5Frequest18470>stage: test needed -> patch review
2020-03-17 22:20:04 scic0 set messages: +
2020-03-17 20:22:17 AkechiShiro set nosy: + AkechiShiromessages: +
2020-02-18 23:05:18 steve.dower set messages: +
2020-02-16 00:31:24 sdcards set nosy: + sdcardsmessages: +
2020-02-08 15:34:54 scic0 set nosy: + scic0messages: +
2020-02-05 22:15:07 Dan Arad set nosy: + Dan Arad
2019-12-02 17:52:35 steve.dower set versions: + Python 3.8, Python 3.9messages: + keywords: + easy, newcomer friendlytype: behaviorstage: test needed
2019-03-20 21:00:58 lazka set versions: + Python 3.7, - Python 3.5
2016-12-02 22:25:52 martin.panter set title: os.path.mount sometimes raises FileNotFoundError on Windows -> os.path.ismount sometimes raises FileNotFoundError on Windows
2016-12-02 16:13:06 wolma set nosy: + wolma
2016-12-02 14:39:20 lazka create