1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/piperutils/FileUtils.go

50 lines
739 B
Go
Raw Normal View History

package piperutils
import (
"errors"
"io"
"os"
)
// FileExists ...
func FileExists(filename string) (bool, error) {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, err
}
return !info.IsDir(), nil
}
// Copy ...
func Copy(src, dst string) (int64, error) {
exists, err := FileExists(src)
if err != nil {
return 0, err
}
if !exists {
return 0, errors.New("Source file '" + src + "' does not exist")
}
source, err := os.Open(src)
if err != nil {
return 0, err
}
defer source.Close()
destination, err := os.Create(dst)
if err != nil {
return 0, err
}
defer destination.Close()
nBytes, err := io.Copy(destination, source)
return nBytes, err
}