1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

utils: Added SelfPath(), which figures out the current (absolute) path of the running binary

This commit is contained in:
Andrea Luzzardi 2013-02-13 13:58:28 -08:00
parent 2416edd400
commit e6adfa2bc6

View file

@ -4,7 +4,9 @@ import (
"bytes" "bytes"
"container/list" "container/list"
"io" "io"
"os"
"os/exec" "os/exec"
"path/filepath"
"sync" "sync"
) )
@ -34,6 +36,19 @@ func Tar(path string) (io.Reader, error) {
return output, nil 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 { type nopWriteCloser struct {
io.Writer io.Writer
} }