From 77a6ab050b53e549029c80b5142a1e7104491d06 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 28 Sep 2022 14:38:14 +0200 Subject: [PATCH] Add path existence check to utils --- utils/fs.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utils/fs.go b/utils/fs.go index e0873a7..87d2d59 100644 --- a/utils/fs.go +++ b/utils/fs.go @@ -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) +}