about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-02-11T17·01+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-02-11T17·11+0000
commitb3b343ebf97998b9ec9035ac528a9bd20d1cca29 (patch)
treeba6df3116d6904b82a52edb62ca4e8a0a9dcfa3a
parent3ae3b6f039c1f1cf23b3aa85eef43486d6cfacfc (diff)
Support utils.FileExists/1
Support predicate for checking if a file exists on disk.
-rw-r--r--gopkgs/utils/utils.go10
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 {