Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds error-checks for general OS errors #238

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions service/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,22 @@ func contains(list []string, item string) bool {
// return pair is a bool flag of whether file was created, and an error
func mkfile(path string) (bool, error) {
st, err := os.Stat(path)
if os.IsNotExist(err) {
file, err := os.OpenFile(path, os.O_CREATE, 0600) // #nosec G304
if err != nil {
if err != nil {
if os.IsNotExist(err) {
file, err := os.OpenFile(path, os.O_CREATE, 0600) // #nosec G304
if err != nil {
log.WithField("path", path).WithError(
err).Error("Unable to create file")
} else {
file.Close() // #nosec G20
log.WithField("path", path).Debug("created file")
return true, nil
}
} else {
log.WithField("path", path).WithError(
err).Error("Unable to create file")
return false, err
}
file.Close() // #nosec G20
log.WithField("path", path).Debug("created file")
return true, nil
return false, err
}
if st.IsDir() {
return false, fmt.Errorf("existing path is a directory")
Expand All @@ -425,14 +431,19 @@ func mkfile(path string) (bool, error) {
// return pair is a bool flag of whether dir was created, and an error
func mkdir(path string) (bool, error) {
st, err := os.Stat(path)
if os.IsNotExist(err) {
if err := os.Mkdir(path, 0750); err != nil {
log.WithField("dir", path).WithError(
if err != nil {
if os.IsNotExist(err) {
if err := os.Mkdir(path, 0750); err != nil {
log.WithField("dir", path).WithError(
err).Error("Unable to create dir")
} else {
log.WithField("path", path).Debug("created directory")
}
} else {
log.WithField("path", path).WithError(
err).Error("Unable to create dir")
return false, err
}
log.WithField("path", path).Debug("created directory")
return true, nil
return false, err
}
if !st.IsDir() {
return false, fmt.Errorf("existing path is not a directory")
Expand Down
6 changes: 3 additions & 3 deletions service/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,11 @@ func (s *service) disconnectVolume(reqID, symID, devID, volumeWWN string) error
nodeUnstageCtx = setLogFields(nodeUnstageCtx, f)
switch s.arrayTransportProtocolMap[symID] {
case Vsphere:
s.fcConnector.DisconnectVolumeByDeviceName(nodeUnstageCtx, deviceName) // #nosec G20
_ = s.fcConnector.DisconnectVolumeByDeviceName(nodeUnstageCtx, deviceName)
case FcTransportProtocol:
s.fcConnector.DisconnectVolumeByDeviceName(nodeUnstageCtx, deviceName) // #nosec G20
_ = s.fcConnector.DisconnectVolumeByDeviceName(nodeUnstageCtx, deviceName)
case IscsiTransportProtocol:
s.iscsiConnector.DisconnectVolumeByDeviceName(nodeUnstageCtx, deviceName) // #nosec G20
_ = s.iscsiConnector.DisconnectVolumeByDeviceName(nodeUnstageCtx, deviceName)
}
cancel()
time.Sleep(disconnectVolumeRetryTime)
Expand Down
Loading