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
Marcus Holl 9cd4950437
Don't swallow error raised from file exists helper method (#1019)
* Don't swallow error raised from file exists helper method

* streamline
2019-12-11 10:13:23 +01:00

50 lines
739 B
Go

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
}