mirror of
https://github.com/safing/portbase
synced 2025-09-04 03:29:59 +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
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
@ -41,3 +43,9 @@ func EnsureDirectory(path string, perm os.FileMode) error {
|
||||||
// other error opening path
|
// other error opening path
|
||||||
return fmt.Errorf("failed to access %s: %w", path, err)
|
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