sys - add IsFileExists

This commit is contained in:
Mahdi Abu Yasmine 2023-11-07 23:18:16 +01:00
parent ef88ea018c
commit eb55a2b266

View File

@ -2,6 +2,7 @@ package sys
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -147,3 +148,11 @@ func IsRunningOnPod() bool {
var bufout bytes.Buffer var bufout bytes.Buffer
return PipeCmd(exec.Command("cat", "/proc/1/cgroup"), exec.Command("grep", "kubepods"), &bufout) == 0 return PipeCmd(exec.Command("cat", "/proc/1/cgroup"), exec.Command("grep", "kubepods"), &bufout) == 0
} }
func IsFileExists(path string) bool {
exists := false
if _, err := os.Open(path); !errors.Is(err, os.ErrNotExist) {
exists = true
}
return exists
}