syncthing/vendor/github.com/kardianos/osext/osext.go

34 lines
873 B
Go
Raw Normal View History

2014-05-02 08:05:48 +00:00
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Extensions to the standard "os" package.
package osext // import "github.com/kardianos/osext"
2014-05-02 08:05:48 +00:00
import "path/filepath"
2015-12-22 08:39:47 +00:00
var cx, ce = executableClean()
func executableClean() (string, error) {
p, err := executable()
return filepath.Clean(p), err
}
2014-05-02 08:05:48 +00:00
// Executable returns an absolute path that can be used to
// re-invoke the current program.
// It may not be valid after the current program exits.
func Executable() (string, error) {
2015-12-22 08:39:47 +00:00
return cx, ce
2014-05-02 08:05:48 +00:00
}
// Returns same path as Executable, returns just the folder
2015-06-15 19:10:18 +00:00
// path. Excludes the executable name and any trailing slash.
2014-05-02 08:05:48 +00:00
func ExecutableFolder() (string, error) {
p, err := Executable()
if err != nil {
return "", err
}
2015-06-15 19:10:18 +00:00
return filepath.Dir(p), nil
2014-05-02 08:05:48 +00:00
}