Skip to content

Commit

Permalink
win32: fix not using "root" path for GetDriveTypeW
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsura authored and pstorz committed Jun 27, 2023
1 parent c066fbb commit 3f31d31
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions core/src/win32/findlib/win32.cc
Expand Up @@ -78,30 +78,30 @@ std::vector<std::wstring> get_win32_volumes(findFILESET* fileset)
char* fname = node->c_str();

std::wstring wname = converter.from_bytes(fname);
std::wstring volume(100, L'\0');
if (DWORD needed = GetFullPathNameW(wname.c_str(), 0, volume.data(), NULL);
needed >= volume.size()) {
volume.resize(needed + 1, '\0');
std::wstring mountpoint(100, L'\0');
if (DWORD needed = GetFullPathNameW(wname.c_str(), 0, mountpoint.data(), NULL);
needed >= mountpoint.size()) {
mountpoint.resize(needed + 1, '\0');
} else if (needed == 0) {
Dmsg1(100, "Could not query the full path length of %s\n", fname);
continue;
}

if (!GetVolumePathNameW(wname.c_str(), volume.data(), volume.capacity())) {
if (!GetVolumePathNameW(wname.c_str(), mountpoint.data(), mountpoint.capacity())) {
Dmsg1(100, "Could not find a mounted volume on %s\n", fname);
continue;
} else {
volume.resize(wcslen(volume.c_str()));
mountpoint.resize(wcslen(mountpoint.c_str()));
}

// GetDriveTypeW expects that there is no trailing slash!
if (volume.back() == L'\\')
{
volume.pop_back();
std::array<wchar_t, 50> volume;
if (!GetVolumeNameForVolumeMountPointW(mountpoint.c_str(), volume.data(), volume.size())) {
Dmsg1(100, "Could not find the volume name for %s\n",
converter.to_bytes(mountpoint.c_str()).c_str());
continue;
}

if (GetDriveTypeW(volume.c_str()) == DRIVE_FIXED) {
volumes.emplace_back(std::move(volume));
if (GetDriveTypeW(volume.data()) == DRIVE_FIXED) {
volumes.emplace_back(std::move(mountpoint));

}
}
Expand Down

0 comments on commit 3f31d31

Please sign in to comment.