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 (
"bytes"
"errors"
"fmt"
"io"
"os"
@ -147,3 +148,11 @@ func IsRunningOnPod() bool {
var bufout bytes.Buffer
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
}