diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-06-17 12:11:24 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-06-17 12:11:24 +0200 |
| commit | 13c5bfcc6ec165fe0cf988a3e92bbd8d8619411b (patch) | |
| tree | fe684281ba2cccdc47b5639f9759b843dc30d2cd /pkg/osutil | |
| parent | 3e647c355289b2beb2df529cc44f42ec31b6d75b (diff) | |
pkg/osutil: add IsExist helper function
Diffstat (limited to 'pkg/osutil')
| -rw-r--r-- | pkg/osutil/osutil.go | 6 | ||||
| -rw-r--r-- | pkg/osutil/osutil_test.go | 18 |
2 files changed, 24 insertions, 0 deletions
diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 3f42dbc12..a9c64ad1c 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -69,3 +69,9 @@ func Abs(path string) string { } return filepath.Join(wd, path) } + +// IsExist returns true if the file name exists. +func IsExist(name string) bool { + _, err := os.Stat(name) + return err == nil || !os.IsNotExist(err) +} diff --git a/pkg/osutil/osutil_test.go b/pkg/osutil/osutil_test.go new file mode 100644 index 000000000..ee4cb6705 --- /dev/null +++ b/pkg/osutil/osutil_test.go @@ -0,0 +1,18 @@ +// Copyright 2017 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package osutil + +import ( + "os" + "testing" +) + +func TestIsExist(t *testing.T) { + if f := os.Args[0]; !IsExist(f) { + t.Fatalf("executable %v does not exist", f) + } + if f := os.Args[0] + "-foo-bar-buz"; IsExist(f) { + t.Fatalf("file %v exists", f) + } +} |
