Skip to content

Commit c653070

Browse files
authored
Merge pull request #2006 from hungnguyen243/fixParsingErrorListingLSSDs
Use strings.Fields for whitespace splitting to fix issues with strings.Split in case of multiple consecutive spaces
2 parents 9c35e66 + fd0122c commit c653070

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pkg/gce-pd-csi-driver/cache.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func fetchRAIDedLocalSsdPath() (string, error) {
4545
return "", fmt.Errorf("Error getting RAIDed device path for Data Cache %v, output:%v", err, string(info))
4646
}
4747
infoString := strings.TrimSpace(string(info))
48-
infoSlice := strings.Split(infoString, " ")
48+
infoSlice := strings.Fields(infoString)
4949

5050
// We want to get the second element in the array (sample: ARRAY /dev/md126 metadata=1.2 name=csi-driver-data-cache UUID=*),
5151
// which is the path to the RAIDed device
@@ -357,7 +357,7 @@ func FetchAllLssds() ([]string, error) {
357357
for _, ssd := range infoList {
358358
ssd = strings.TrimSpace(ssd)
359359
if strings.HasPrefix(ssd, "/dev/nvme") {
360-
ssdDetails := strings.Split(ssd, " ")
360+
ssdDetails := strings.Fields(ssd)
361361
lssd := re.MatchString(ssdDetails[1])
362362
if lssd {
363363
diskList = append(diskList, strings.TrimSpace(ssdDetails[0]))

0 commit comments

Comments
 (0)