mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Add path existence check to utils
This commit is contained in:
parent
beaa7482d0
commit
77a6ab050b
1 changed files with 8 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue