diff options
author | William Carroll <wpcarro@gmail.com> | 2020-02-11T17·01+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-02-11T17·11+0000 |
commit | b3b343ebf97998b9ec9035ac528a9bd20d1cca29 (patch) | |
tree | ba6df3116d6904b82a52edb62ca4e8a0a9dcfa3a /gopkgs | |
parent | 3ae3b6f039c1f1cf23b3aa85eef43486d6cfacfc (diff) |
Support utils.FileExists/1
Support predicate for checking if a file exists on disk.
Diffstat (limited to 'gopkgs')
-rw-r--r-- | gopkgs/utils/utils.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gopkgs/utils/utils.go b/gopkgs/utils/utils.go index 7ac9defa6f0f..24121ed44c75 100644 --- a/gopkgs/utils/utils.go +++ b/gopkgs/utils/utils.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "net/http/httputil" + "os" "os/user" ) @@ -19,6 +20,15 @@ func HomeDir() string { return user.HomeDir } +// Return true if `path` exists and false otherwise. +func FileExists(path string) bool { + if _, err := os.Stat(path); os.IsNotExist(err) { + return false + } else { + return true + } +} + // Call log.Fatal with `err` when it's not nil. func FailOn(err error) { if err != nil { |