You've already forked sap-jenkins-library
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:
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/SAP/jenkins-library/pkg/config"
|
||||
"github.com/SAP/jenkins-library/pkg/piperutils"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -54,7 +55,7 @@ func generateConfig() error {
|
||||
}
|
||||
|
||||
var customConfig io.ReadCloser
|
||||
if fileExists(GeneralConfig.CustomConfig) {
|
||||
if piperutils.FileExists(GeneralConfig.CustomConfig) {
|
||||
customConfig, err = configOptions.openFile(GeneralConfig.CustomConfig)
|
||||
if err != nil {
|
||||
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
|
||||
return nil, metadata.GetParameterFilters(), nil
|
||||
}
|
||||
|
||||
func fileExists(filename string) bool {
|
||||
info, err := os.Stat(filename)
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return !info.IsDir()
|
||||
}
|
||||
|
14
pkg/piperutils/FileUtils.go
Normal file
14
pkg/piperutils/FileUtils.go
Normal 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()
|
||||
}
|
Reference in New Issue
Block a user