Skip to content

Commit ee409e4

Browse files
authored
Merge pull request #55 from hakril/volume_dospath_fix
Change LogicalDrive.path logic based on QueryDosDevice returned valudes
2 parents 328735b + f957c64 commit ee409e4

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

windows/winobject/volume.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@ def path(self):
3939
"""The target path of the device
4040
4141
:type: :class:`str`"""
42-
res = query_dos_device(self.name.strip("\\"))
43-
if len(res) != 1:
44-
raise ValueError("[Unexpected result] query_dos_device(logicaldrive) returned multiple path")
45-
return res[0]
42+
# QueryDosDevice can returns multiple path if DefineDosDevice(AW) was used before
43+
# Looks like its per-process
44+
# But in ths cas the first entry is the effective-one and the others are the previous entries
45+
# https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-querydosdevicea
46+
# The first null-terminated string stored into the buffer is the current mapping for the device. The other null-terminated strings represent undeleted prior mappings for the device.
47+
return query_dos_device(self.name.strip("\\"))[0]
48+
49+
@property
50+
def query_dos_device(self):
51+
return query_dos_device(self.name.strip("\\"))
4652

4753
def query_info(self, info):
4854
return windows.utils.query_volume_information(self.handle, info)

0 commit comments

Comments
 (0)