@cryptotaxi247 / kubo / commits / 11fd2aa70

feat(util) FileExists

License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Nov 16, 2014 at 13:11 UTC 11fd2aa701b35158a8c2b40a01660d7916b72ae0
2 files changed +21
util/file.go new
+11
@@ -0,0 +1,11 @@
1 +package util
2 +
3 +import "os"
4 +
5 +func FileExists(filename string) bool {
6 + fi, err := os.Lstat(filename)
7 + if fi != nil || (err != nil && !os.IsNotExist(err)) {
8 + return true
9 + }
10 + return false
11 +}
util/file_test.go new
+10
@@ -0,0 +1,10 @@
1 +package util
2 +
3 +import "testing"
4 +
5 +func TestFileDoesNotExist(t *testing.T) {
6 + t.Parallel()
7 + if FileExists("i would be surprised to discover that this file exists") {
8 + t.Fail()
9 + }
10 +}