aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/osutil/osutil.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-09-24 10:04:02 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-09-25 15:19:06 +0200
commitdcf893f99cdcead3d82e987953341caa030b30f9 (patch)
tree7a5303ffd6208b27d39a1bdb631e3513e828ce2d /pkg/osutil/osutil.go
parent4a0022152693f8c10ef0b894bcc275fb19b5b5ba (diff)
pkg/osutil: windows port
Diffstat (limited to 'pkg/osutil/osutil.go')
-rw-r--r--pkg/osutil/osutil.go28
1 files changed, 28 insertions, 0 deletions
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)
+}