Skip to content

Commit 4a4d032

Browse files
authored
Merge pull request #15 from 27149chen/fix/use_os_is_not_exist
use os.IsNotExist and other small fixes
2 parents 1efb74c + 7458a41 commit 4a4d032

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

iscsi/iscsi.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,12 @@ func sessionExists(tgtPortal, tgtIQN string) (bool, error) {
102102
if err != nil {
103103
return false, err
104104
}
105-
var existingSessions []iscsiSession
106105
for _, s := range sessions {
107106
if tgtIQN == s.IQN && tgtPortal == s.Portal {
108-
existingSessions = append(existingSessions, s)
107+
return true, nil
109108
}
110109
}
111-
exists := false
112-
if len(existingSessions) > 0 {
113-
exists = true
114-
}
115-
return exists, nil
110+
return false, nil
116111
}
117112

118113
func extractTransportName(output string) string {
@@ -136,8 +131,8 @@ func getCurrentSessions() ([]iscsiSession, error) {
136131
}
137132
return nil, err
138133
}
139-
session := parseSessions(out)
140-
return session, err
134+
sessions := parseSessions(out)
135+
return sessions, err
141136
}
142137

143138
func waitForPathToExist(devicePath *string, maxRetries, intervalSeconds int, deviceTransport string) (bool, error) {
@@ -154,7 +149,7 @@ func waitForPathToExistImpl(devicePath *string, maxRetries, intervalSeconds int,
154149
err = nil
155150
if deviceTransport == "tcp" {
156151
_, err = osStat(*devicePath)
157-
if err != nil && !strings.Contains(err.Error(), "no such file or directory") {
152+
if err != nil && !os.IsNotExist(err) {
158153
debug.Printf("Error attempting to stat device: %s", err.Error())
159154
return false, err
160155
} else if err != nil {

0 commit comments

Comments
 (0)