on main help sign in
fix: only enable built-in core utils by default on windows
569044cAndrey Nering
internal/shell/coreutils.gonew file+19
@@ -0,0 +1,19 @@
1+package shell
2+
3+import (
4+ "os"
5+ "runtime"
6+ "strconv"
7+)
8+
9+var useGoCoreUtils bool
10+
11+func init() {
12+ // If CRUSH_CORE_UTILS is set to either true or false, respect that.
13+ // By default, enable on Windows only.
14+ if v, err := strconv.ParseBool(os.Getenv("CRUSH_CORE_UTILS")); err == nil {
15+ useGoCoreUtils = v
16+ } else {
17+ useGoCoreUtils = runtime.GOOS == "windows"
18+ }
19+}
internal/shell/shell.go+11−1
@@ -241,7 +241,7 @@ func (s *Shell) execPOSIX(ctx context.Context, command string) (string, string,
241 interp.Interactive(false),
241 interp.Interactive(false),
242 interp.Env(expand.ListEnviron(s.env...)),
242 interp.Env(expand.ListEnviron(s.env...)),
243 interp.Dir(s.cwd),
243 interp.Dir(s.cwd),
244− interp.ExecHandlers(s.blockHandler(), coreutils.ExecHandler),
244+ interp.ExecHandlers(s.execHandlers()...),
245 )
245 )
246 if err != nil {
246 if err != nil {
247 return "", "", fmt.Errorf("could not run command: %w", err)
247 return "", "", fmt.Errorf("could not run command: %w", err)
@@ -257,6 +257,16 @@ func (s *Shell) execPOSIX(ctx context.Context, command string) (string, string,
257 return stdout.String(), stderr.String(), err
257 return stdout.String(), stderr.String(), err
258}
258}
259
259
260+func (s *Shell) execHandlers() []func(next interp.ExecHandlerFunc) interp.ExecHandlerFunc {
261+ handlers := []func(next interp.ExecHandlerFunc) interp.ExecHandlerFunc{
262+ s.blockHandler(),
263+ }
264+ if useGoCoreUtils {
265+ handlers = append(handlers, coreutils.ExecHandler)
266+ }
267+ return handlers
268+}
269+
260// IsInterrupt checks if an error is due to interruption
270// IsInterrupt checks if an error is due to interruption
261func IsInterrupt(err error) bool {
271func IsInterrupt(err error) bool {
262 return errors.Is(err, context.Canceled) ||
272 return errors.Is(err, context.Canceled) ||