diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-02-17 13:17:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-17 13:17:34 -0500 |
commit | 6ea9ff2f21b583e4bc61a72d97c889ee7057a32e (patch) | |
tree | d378b355d2357ec41e03d4c7ead9d359a9336345 /vendor/github.com/magefile/mage/sh/helpers.go | |
parent | 516dc6d1ff618019079bc68055dd7f6c2a447aa2 (diff) | |
parent | 6842907250e84b2b315a7fa609b52f20258ebfa1 (diff) | |
download | podman-6ea9ff2f21b583e4bc61a72d97c889ee7057a32e.tar.gz podman-6ea9ff2f21b583e4bc61a72d97c889ee7057a32e.tar.bz2 podman-6ea9ff2f21b583e4bc61a72d97c889ee7057a32e.zip |
Merge pull request #9406 from containers/dependabot/go_modules/github.com/sirupsen/logrus-1.7.1
Bump github.com/sirupsen/logrus from 1.7.0 to 1.7.1
Diffstat (limited to 'vendor/github.com/magefile/mage/sh/helpers.go')
-rw-r--r-- | vendor/github.com/magefile/mage/sh/helpers.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/github.com/magefile/mage/sh/helpers.go b/vendor/github.com/magefile/mage/sh/helpers.go new file mode 100644 index 000000000..f5d20a271 --- /dev/null +++ b/vendor/github.com/magefile/mage/sh/helpers.go @@ -0,0 +1,40 @@ +package sh + +import ( + "fmt" + "io" + "os" +) + +// Rm removes the given file or directory even if non-empty. It will not return +// an error if the target doesn't exist, only if the target cannot be removed. +func Rm(path string) error { + err := os.RemoveAll(path) + if err == nil || os.IsNotExist(err) { + return nil + } + return fmt.Errorf(`failed to remove %s: %v`, path, err) +} + +// Copy robustly copies the source file to the destination, overwriting the destination if necessary. +func Copy(dst string, src string) error { + from, err := os.Open(src) + if err != nil { + return fmt.Errorf(`can't copy %s: %v`, src, err) + } + defer from.Close() + finfo, err := from.Stat() + if err != nil { + return fmt.Errorf(`can't stat %s: %v`, src, err) + } + to, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, finfo.Mode()) + if err != nil { + return fmt.Errorf(`can't copy to %s: %v`, dst, err) + } + defer to.Close() + _, err = io.Copy(to, from) + if err != nil { + return fmt.Errorf(`error copying %s to %s: %v`, src, dst, err) + } + return nil +} |