Skip to content

Commit 211296e

Browse files
committed
Update windows minikube load to include fallback
Enhance new Powershell Get-CimInstance call to fetch the volume guid with a fallback method to the old deprecated wmic.exe method for consistency.
1 parent 8b7687e commit 211296e

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

pkg/minikube/localpath/localpath.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,48 @@ func getWindowsVolumeNameCmd(d string) (string, error) {
198198
var out bytes.Buffer
199199
cmd.Stdout = &out
200200

201-
err := cmd.Run()
201+
psErr := cmd.Run()
202+
if psErr == nil {
203+
vname := strings.TrimSpace(out.String())
204+
if strings.HasPrefix(vname, `\\?\Volume{`) && strings.HasSuffix(vname, `}\`) {
205+
return vname, nil
206+
}
207+
// PowerShell succeeded but returned invalid output, try WMIC
208+
wmicResult, wmicErr := getWindowsVolumeNameWMIC(d)
209+
if wmicErr != nil {
210+
return "", errors.Wrapf(wmicErr, "PowerShell returned invalid volume GUID format, WMIC also failed")
211+
}
212+
return wmicResult, nil
213+
}
214+
215+
// PowerShell failed, fall back to WMIC
216+
wmicResult, wmicErr := getWindowsVolumeNameWMIC(d)
217+
if wmicErr != nil {
218+
return "", errors.Wrapf(wmicErr, "PowerShell failed (%v), WMIC also failed", psErr)
219+
}
220+
return wmicResult, nil
221+
}
222+
223+
func getWindowsVolumeNameWMIC(d string) (string, error) {
224+
cmd := exec.Command("wmic", "volume", "where", "DriveLetter = '"+d+":'", "get", "DeviceID")
225+
226+
stdout, err := cmd.Output()
202227
if err != nil {
203228
return "", err
204229
}
205230

206-
vname := strings.TrimSpace(out.String())
207-
if !strings.HasPrefix(vname, `\\?\Volume{`) || !strings.HasSuffix(vname, `}\`) {
231+
outs := strings.Split(strings.ReplaceAll(string(stdout), "\r", ""), "\n")
232+
233+
var vname string
234+
for _, l := range outs {
235+
s := strings.TrimSpace(l)
236+
if strings.HasPrefix(s, `\\?\Volume{`) && strings.HasSuffix(s, `}\`) {
237+
vname = s
238+
break
239+
}
240+
}
241+
242+
if vname == "" {
208243
return "", errors.New("failed to get a volume GUID")
209244
}
210245

0 commit comments

Comments
 (0)