Add path existence check to utils

This commit is contained in:
Daniel 2022-09-28 14:38:14 +02:00
parent beaa7482d0
commit 77a6ab050b

View file

@ -1,7 +1,9 @@
package utils
import (
"errors"
"fmt"
"io/fs"
"os"
"runtime"
)
@ -41,3 +43,9 @@ func EnsureDirectory(path string, perm os.FileMode) error {
// other error opening path
return fmt.Errorf("failed to access %s: %w", path, err)
}
// PathExists returns whether the given path (file or dir) exists.
func PathExists(path string) bool {
_, err := os.Stat(path)
return err == nil || errors.Is(err, fs.ErrExist)
}