From e6adfa2bc68db8f1f1ccd9facea6fa8f8bed4a33 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Wed, 13 Feb 2013 13:58:28 -0800 Subject: [PATCH] utils: Added SelfPath(), which figures out the current (absolute) path of the running binary --- utils.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utils.go b/utils.go index b021ef8c03..10c617d806 100644 --- a/utils.go +++ b/utils.go @@ -4,7 +4,9 @@ import ( "bytes" "container/list" "io" + "os" "os/exec" + "path/filepath" "sync" ) @@ -34,6 +36,19 @@ func Tar(path string) (io.Reader, error) { return output, nil } +// Figure out the absolute path of our own binary +func SelfPath() string { + path, err := exec.LookPath(os.Args[0]) + if err != nil { + panic(err) + } + path, err = filepath.Abs(path) + if err != nil { + panic(err) + } + return path +} + type nopWriteCloser struct { io.Writer }