-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for windows, which mostly consists of correctly handling path names, path lookups and signals.
- Loading branch information
1 parent
dde4a1b
commit 582223f
Showing
31 changed files
with
932 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2021 cloudeng llc. All rights reserved. | ||
// Use of this source code is governed by the Apache-2.0 | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package flagvar | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// ExpandEnv is like os.ExpandEnv but supports 'pseudo' environment | ||
// variables that have OS specific handling as follows: | ||
// | ||
// On Windows $HOME and $PATH are replaced by and $HOMEDRIVE:\\$HOMEPATH | ||
// and $Path respectively. | ||
// On Windows /'s are replaced with \'s. | ||
func ExpandEnv(e string) string { | ||
return os.ExpandEnv(e) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2021 cloudeng llc. All rights reserved. | ||
// Use of this source code is governed by the Apache-2.0 | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build windows | ||
// +build windows | ||
|
||
package flagvar | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
// ExpandEnv is like os.ExpandEnv but supports 'pseudo' environment | ||
// variables that have OS specific handling as follows: | ||
// | ||
// On Windows $HOME and $PATH are replaced by and $HOMEDRIVE:\\$HOMEPATH | ||
// and $Path respectively. | ||
// On Windows /'s are replaced with \'s. | ||
func ExpandEnv(e string) string { | ||
e = strings.ReplaceAll(e, "$HOME", `$HOMEDRIVE$HOMEPATH`) | ||
return strings.ReplaceAll(os.ExpandEnv(e), `/`, `\`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2015 The Vanadium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package gosh_test | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"strings" | ||
"syscall" | ||
"testing" | ||
"time" | ||
|
||
"v.io/x/lib/gosh" | ||
) | ||
|
||
func TestCleanupProcessGroup(t *testing.T) { | ||
sh := gosh.NewShell(t) | ||
defer sh.Cleanup() | ||
|
||
c := sh.FuncCmd(processGroup, 5) | ||
c.Start() | ||
pids := c.AwaitVars("pids")["pids"] | ||
c.Signal(os.Interrupt) | ||
|
||
// Wait for all processes in the child's process group to exit. | ||
for syscall.Kill(-c.Pid(), 0) != syscall.ESRCH { | ||
time.Sleep(100 * time.Millisecond) | ||
} | ||
for _, pid := range strings.Split(pids, ",") { | ||
p, _ := strconv.Atoi(pid) | ||
eq(t, syscall.Kill(p, 0), syscall.ESRCH) | ||
} | ||
} |
Oops, something went wrong.