Skip to content

Commit

Permalink
Handle alternate NT path forms
Browse files Browse the repository at this point in the history
`convert_dos_path` does not currently handle UNC paths or paths of the form `\??\X:` (as returned by Wine).
This results in the `psutil/tests/test_process.py::TestProcess::test_exe` test failing in the following cases:
* Python is run from a network share; or
* The tests are performed under Wine on a drive other than the one Python is installed on.

Add handling for the following NT path forms:
* `\\server\share`
* `\Device\Mup\server\share` -> `\\server\share`
* `\??\UNC\server\share` -> `\\server\share`
* `\??\X:` -> `X:`

Signed-off-by: Ben Peddell <[email protected]>
  • Loading branch information
klightspeed committed Jan 3, 2025
1 parent d9b2bac commit b38f747
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,21 @@ class IOPriority(enum.IntEnum):
@functools.lru_cache(maxsize=512)
def convert_dos_path(s):
r"""Convert paths using native DOS format like:
"\Device\HarddiskVolume1\Windows\systemew\file.txt"
"\Device\HarddiskVolume1\Windows\systemew\file.txt" or
"\??\C:\Windows\systemew\file.txt"
into:
"C:\Windows\systemew\file.txt".
"""
if s[:2] == '\\\\':
return s
rawdrive = '\\'.join(s.split('\\')[:3])
driveletter = cext.QueryDosDevice(rawdrive)
if rawdrive in {"\\??\\UNC", "\\Device\\Mup"}:
rawdrive = '\\'.join(s.split('\\')[:4])
driveletter = "\\\\" + s.split('\\')[3]
elif rawdrive[:4] == '\\??\\':
driveletter = rawdrive[4:]
else:
driveletter = cext.QueryDosDevice(rawdrive)
remainder = s[len(rawdrive) :]
return os.path.join(driveletter, remainder)

Expand Down

0 comments on commit b38f747

Please sign in to comment.