Skip to content

Commit 0b9d6a8

Browse files
author
Lou
committed
use os.IsNotExist and other small fixes
Signed-off-by: Lou <[email protected]>
1 parent 1430b53 commit 0b9d6a8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

iscsi/iscsi.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,10 @@ func sessionExists(tgtPortal, tgtIQN string) (bool, error) {
9999
var existingSessions []iscsiSession
100100
for _, s := range sessions {
101101
if tgtIQN == s.IQN && tgtPortal == s.Portal {
102-
existingSessions = append(existingSessions, s)
102+
return true, nil
103103
}
104104
}
105-
exists := false
106-
if len(existingSessions) > 0 {
107-
exists = true
108-
}
109-
return exists, nil
105+
return false, nil
110106
}
111107

112108
func extractTransportName(output string) string {
@@ -130,8 +126,8 @@ func getCurrentSessions() ([]iscsiSession, error) {
130126
}
131127
return nil, err
132128
}
133-
session := parseSessions(out)
134-
return session, err
129+
sessions := parseSessions(out)
130+
return sessions, err
135131
}
136132

137133
func waitForPathToExist(devicePath *string, maxRetries, intervalSeconds int, deviceTransport string) (bool, error) {
@@ -148,7 +144,7 @@ func waitForPathToExistImpl(devicePath *string, maxRetries, intervalSeconds int,
148144
err = nil
149145
if deviceTransport == "tcp" {
150146
_, err = osStat(*devicePath)
151-
if err != nil && !strings.Contains(err.Error(), "no such file or directory") {
147+
if err != nil && !os.IsNotExist(err) {
152148
debug.Printf("Error attempting to stat device: %s", err.Error())
153149
return false, err
154150
} else if err != nil {

0 commit comments

Comments
 (0)