From dcf893f99cdcead3d82e987953341caa030b30f9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 24 Sep 2017 10:04:02 +0200 Subject: pkg/osutil: windows port --- pkg/osutil/osutil.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'pkg/osutil/osutil.go') diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 79cd455c2..d98e91e19 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "time" ) @@ -145,3 +146,30 @@ func ListDir(dir string) ([]string, error) { defer f.Close() return f.Readdirnames(-1) } + +var wd string + +func init() { + if runtime.GOOS == "fuchsia" { + return + } + var err error + wd, err = os.Getwd() + if err != nil { + panic(fmt.Sprintf("failed to get wd: %v", err)) + } +} + +func Abs(path string) string { + if runtime.GOOS == "fuchsia" { + // Getwd/Abs are not supported on fuchsia. Let's hope for best. + return path + } + if wd1, err := os.Getwd(); err == nil && wd1 != wd { + panic("don't mess with wd in a concurrent program") + } + if path == "" || filepath.IsAbs(path) { + return path + } + return filepath.Join(wd, path) +} -- cgit mrf-deployment