From da4463b3833c281ba2225e2a03afe61965ea03b2 Mon Sep 17 00:00:00 2001 From: PrasantDell <51162948+prasant123@users.noreply.github.com> Date: Sat, 24 Feb 2024 17:33:42 +0530 Subject: [PATCH] Finding drive vid in lsblk vendor (#1094) * Finding drive vid in lsblk vendor * addressing review comments * Initializing device --------- Signed-off-by: Andrzej Zukowski --- pkg/base/linuxutils/lsblk/lsblk.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pkg/base/linuxutils/lsblk/lsblk.go b/pkg/base/linuxutils/lsblk/lsblk.go index 5ba5308b6..ac49f0b94 100644 --- a/pkg/base/linuxutils/lsblk/lsblk.go +++ b/pkg/base/linuxutils/lsblk/lsblk.go @@ -161,12 +161,8 @@ func (l *LSBLK) GetBlockDevices(device string) ([]BlockDevice, error) { // Receives an instance of drivecrd.Drive struct // Returns drive's path based on provided drivecrd.Drive or error if something went wrong func (l *LSBLK) SearchDrivePath(drive *api.Drive) (string, error) { - // device path might be already set by hwmgr - device := drive.Path - if device != "" { - return device, nil - } + device := "" // try to find it with lsblk lsblkOut, err := l.GetBlockDevices("") if err != nil { @@ -178,8 +174,9 @@ func (l *LSBLK) SearchDrivePath(drive *api.Drive) (string, error) { vid := drive.VID pid := drive.PID for _, l := range lsblkOut { - if strings.EqualFold(l.Serial, sn) && strings.EqualFold(l.Vendor, vid) && - strings.EqualFold(l.Model, pid) { + lvid := strings.TrimSpace(l.Vendor) + if strings.EqualFold(l.Serial, sn) && strings.EqualFold(lvid, vid) && + strings.HasPrefix(l.Model, pid) { device = l.Name break }