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

gh-117114: Add isdevdrive to posixpath #117115

Merged
merged 11 commits into from
Mar 25, 2024
11 changes: 10 additions & 1 deletion Lib/genericpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
'getsize', 'isdir', 'isfile', 'islink', 'samefile', 'sameopenfile',
'samestat']
'samestat','lexists']


# Does a path exist?
Expand All @@ -22,6 +22,15 @@ def exists(path):
return True


# Being true for dangling symbolic links is also useful.
def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
os.lstat(path)
except (OSError, ValueError):
return False
return True

# This follows symbolic links, so both islink() and isdir() can be true
# for the same path on systems that support symlinks
def isfile(path):
Expand Down
13 changes: 2 additions & 11 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"ismount","isreserved","expanduser","expandvars","normpath",
"abspath","curdir","pardir","sep","pathsep","defpath","altsep",
"extsep","devnull","realpath","supports_unicode_filenames","relpath",
"samefile", "sameopenfile", "samestat", "commonpath", "isjunction"]
"samefile", "sameopenfile", "samestat", "commonpath", "isjunction",
"isdevdrive"]

def _get_bothseps(path):
if isinstance(path, bytes):
Expand Down Expand Up @@ -286,16 +287,6 @@ def isjunction(path):
return False


# Being true for dangling symbolic links is also useful.

def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
st = os.lstat(path)
except (OSError, ValueError):
return False
return True

# Is a path a mount point?
# Any drive letter root (eg c:\)
# Any share UNC (eg \\server\share)
Expand Down
16 changes: 5 additions & 11 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"samefile","sameopenfile","samestat",
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
"devnull","realpath","supports_unicode_filenames","relpath",
"commonpath", "isjunction"]
"commonpath", "isjunction","isdevdrive"]


def _get_sep(path):
Expand Down Expand Up @@ -196,16 +196,10 @@ def isjunction(path):
return False


# Being true for dangling symbolic links is also useful.

def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
os.lstat(path)
except (OSError, ValueError):
return False
return True

def isdevdrive(path):
"""Determines whether the specified path is on a Dev Drive.
Dev Drives are not a part of posix semantics"""
return False

# Is a path a mount point?
# (Does this work for all UNIXes? Is it even guaranteed to work by Posix?)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added posix implementation for isdevdrive.
nineteendo marked this conversation as resolved.
Show resolved Hide resolved
Loading