Skip to content

Commit

Permalink
ut fix
Browse files Browse the repository at this point in the history
  • Loading branch information
suryagupta4 committed Oct 17, 2023
1 parent 9335fad commit 78032e9
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion service/ephemeral.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (s *service) ephemeralNodePublish(

_, err := os.Stat(ephemeralStagingMountPath)
if err != nil {
Log.Warnf("Unable to check stat of file: %s with error: %v", ephemeralStagingMountPath, err.Error())
if os.IsNotExist(err) {
Log.Debug("path does not exist, will attempt to create it")
err = os.MkdirAll(ephemeralStagingMountPath, 0750)
Expand All @@ -71,7 +72,6 @@ func (s *service) ephemeralNodePublish(
return nil, status.Error(codes.Internal, "Unable to create directory for mounting ephemeral volumes")
}
}
Log.Errorf("Unable to check stat of file: %s with error: %v", ephemeralStagingMountPath, err.Error())
}

volID := req.GetVolumeId()
Expand Down
4 changes: 2 additions & 2 deletions service/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ func contains(list []string, item string) bool {
func mkfile(path string) (bool, error) {
st, err := os.Stat(path)
if err != nil {
Log.Infof("Unable to check stat of file: %s with error: %v", path, err.Error())
if os.IsNotExist(err) {
/* #nosec G302 G304 */
file, err := os.OpenFile(path, os.O_CREATE, 0755)
Expand All @@ -568,7 +569,6 @@ func mkfile(path string) (bool, error) {
Log.WithField("path", path).Debug("created file")
return true, nil
}
Log.Errorf("Unable to check stat of file: %s with error: %v", path, err.Error())
}
if st.IsDir() {
return false, fmt.Errorf("existing path is a directory")
Expand All @@ -581,6 +581,7 @@ func mkfile(path string) (bool, error) {
func mkdir(path string) (bool, error) {
st, err := os.Stat(path)
if err != nil {
Log.Warnf("Unable to check stat of file: %s with error: %v", path, err.Error())
if os.IsNotExist(err) {
err := os.Mkdir(path, 0755) // #nosec G301
if err != nil {
Expand All @@ -591,7 +592,6 @@ func mkdir(path string) (bool, error) {
Log.WithField("path", path).Debug("created directory")
return true, nil
}
Log.Errorf("Unable to check stat of file: %s with error: %v", path, err.Error())
}
if !st.IsDir() {
return false, fmt.Errorf("existing path is not a directory")
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,10 @@ func getArrayConfig(ctx context.Context) (map[string]*ArrayConnectionData, error

_, err := os.Stat(ArrayConfigFile)
if err != nil {
Log.Errorf("Found error %v while checking stat of file %s ", err, ArrayConfigFile)
if os.IsNotExist(err) {
return nil, fmt.Errorf(fmt.Sprintf("File %s does not exist", ArrayConfigFile))
}
fmt.Printf("Found error %v while checking stat of file %s ", err, ArrayConfigFile)
}

config, err := os.ReadFile(filepath.Clean(ArrayConfigFile))
Expand Down
1 change: 0 additions & 1 deletion test/integration/step_defs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func (f *feature) getArrayConfig() (map[string]*ArrayConnectionData, error) {
if os.IsNotExist(err) {
return nil, fmt.Errorf(fmt.Sprintf("File %s does not exist", configFile))
}
fmt.Printf("Found error %v while checking stat of file %s ", err, configFile)
}

config, err := os.ReadFile(filepath.Clean(configFile))
Expand Down

0 comments on commit 78032e9

Please sign in to comment.