123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package utils
-
- import (
- "io"
- "os"
- "os/exec"
- "strconv"
- )
-
- // FileExists check file is exists
- func FileExists(path string) bool {
- _, err := os.Stat(path)
- if err != nil {
- if os.IsExist(err) {
- return true
- }
- return false
- }
- return true
- }
-
- // PidExists checkou process id is exists
- func PidExists(pid int) bool {
- out, _ := exec.Command("kill", "-s", "0", strconv.Itoa(pid)).CombinedOutput()
- if string(out) == "" {
- return true // pid exist
- }
- return false
- }
-
- // CopyFile copy file from src to dest
- func CopyFile(srcFile, destFile string) error {
- file, err := os.Open(srcFile)
- if err != nil {
- return err
- }
-
- defer file.Close()
-
- dest, err := os.Create(destFile)
- if err != nil {
- return err
- }
-
- defer dest.Close()
-
- _, err = io.Copy(dest, file)
- if err != nil {
- return err
- }
-
- return nil
- }
|