1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-09-16 09:26:22 +02:00

Helper for fileExists (#954)

Since we need it at several places (next use case will be step xsDeploy) we should
have a helper for that.
This commit is contained in:
Marcus Holl
2019-11-07 08:17:42 +01:00
committed by GitHub
parent ede322c8bb
commit 7c5a8a73bc
2 changed files with 16 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ import (
"os" "os"
"github.com/SAP/jenkins-library/pkg/config" "github.com/SAP/jenkins-library/pkg/config"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@@ -54,7 +55,7 @@ func generateConfig() error {
} }
var customConfig io.ReadCloser var customConfig io.ReadCloser
if fileExists(GeneralConfig.CustomConfig) { if piperutils.FileExists(GeneralConfig.CustomConfig) {
customConfig, err = configOptions.openFile(GeneralConfig.CustomConfig) customConfig, err = configOptions.openFile(GeneralConfig.CustomConfig)
if err != nil { if err != nil {
return errors.Wrap(err, "config: open failed") return errors.Wrap(err, "config: open failed")
@@ -119,11 +120,3 @@ func defaultsAndFilters(metadata *config.StepData) ([]io.ReadCloser, config.Step
//ToDo: retrieve default values from metadata //ToDo: retrieve default values from metadata
return nil, metadata.GetParameterFilters(), nil return nil, metadata.GetParameterFilters(), nil
} }
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

View File

@@ -0,0 +1,14 @@
package piperutils
import (
"os"
)
// FileExists ...
func FileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}