|
4 | 4 | package runner |
5 | 5 |
|
6 | 6 | import ( |
7 | | - "context" |
8 | 7 | "os" |
9 | 8 | "os/exec" |
10 | | - "path/filepath" |
11 | 9 | "syscall" |
12 | 10 |
|
13 | 11 | "github.com/buildbarn/bb-remote-execution/pkg/proto/resourceusage" |
14 | | - "github.com/buildbarn/bb-storage/pkg/filesystem/path" |
15 | | - "github.com/buildbarn/bb-storage/pkg/util" |
16 | 12 |
|
17 | 13 | "golang.org/x/sys/windows" |
18 | 14 | "google.golang.org/grpc/codes" |
19 | 15 | "google.golang.org/grpc/status" |
20 | 16 | "google.golang.org/protobuf/types/known/durationpb" |
21 | 17 | ) |
22 | 18 |
|
23 | | -// NewPlainCommandCreator returns a CommandCreator for cases where we don't |
24 | | -// need to chroot into the input root directory. |
25 | | -func NewPlainCommandCreator(sysProcAttr *syscall.SysProcAttr) CommandCreator { |
26 | | - return func(ctx context.Context, arguments []string, inputRootDirectory *path.Builder, workingDirectoryParser path.Parser, pathVariable string) (*exec.Cmd, error) { |
27 | | - // TODO: This may not work correctly if the action sets |
28 | | - // the PATH environment variable explicitly. |
29 | | - // |
30 | | - // exec.CommandContext() has some smartness to call |
31 | | - // exec.LookPath() under the hood, which we don't want. |
32 | | - // Call it with a placeholder path, followed by setting |
33 | | - // cmd.Path and cmd.Args manually. This ensures that our |
34 | | - // own values remain respected. |
35 | | - argv0 := arguments[0] |
36 | | - |
37 | | - pathBuilder, scopeWalker := path.EmptyBuilder.Join(path.VoidScopeWalker) |
38 | | - if err := path.Resolve(path.NewLocalParser(argv0), scopeWalker); err != nil { |
39 | | - return nil, err |
40 | | - } |
41 | | - argv0, err := pathBuilder.GetWindowsString() |
42 | | - if err != nil { |
43 | | - return nil, err |
44 | | - } |
45 | | - |
46 | | - arguments[0] = "\\nonexistent-place-back-later" |
47 | | - cmd := exec.CommandContext(ctx, arguments[0], arguments[1:]...) |
48 | | - cmd.SysProcAttr = sysProcAttr |
49 | | - |
50 | | - // Set the working relative to be relative to the input |
51 | | - // root directory. |
52 | | - workingDirectory, scopeWalker := inputRootDirectory.Join(path.VoidScopeWalker) |
53 | | - if err := path.Resolve(workingDirectoryParser, scopeWalker); err != nil { |
54 | | - return nil, util.StatusWrap(err, "Failed to resolve working directory") |
55 | | - } |
56 | | - workingDirectoryStr, err := path.GetLocalString(workingDirectory) |
57 | | - if err != nil { |
58 | | - return nil, util.StatusWrap(err, "Failed to create local representation of working directory") |
59 | | - } |
60 | | - cmd.Dir = workingDirectoryStr |
61 | | - |
62 | | - executablePath, err := lookupExecutable(workingDirectory, pathVariable, argv0) |
63 | | - if err != nil { |
64 | | - return nil, err |
65 | | - } |
66 | | - |
67 | | - // Must use backslashes to execute relative paths |
68 | | - executablePath = filepath.FromSlash(executablePath) |
69 | | - arguments[0] = executablePath |
70 | | - |
71 | | - cmd.Args = arguments |
72 | | - cmd.Path = executablePath |
73 | | - cmd.SysProcAttr = sysProcAttr |
74 | | - return cmd, nil |
75 | | - } |
76 | | -} |
77 | | - |
78 | 19 | // NewChrootedCommandCreator gives an error on Windows, as chroot is not |
79 | 20 | // supported on the platform. |
80 | 21 | func NewChrootedCommandCreator(sysProcAttr *syscall.SysProcAttr) (CommandCreator, error) { |
81 | | - return nil, status.Error(codes.InvalidArgument, "Chroot not supported on Windows") |
| 22 | + return nil, status.Error(codes.InvalidArgument, "Chroot is not supported on Windows") |
82 | 23 | } |
83 | 24 |
|
84 | 25 | var temporaryDirectoryEnvironmentVariablePrefixes = [...]string{"TMP=", "TEMP="} |
|
0 commit comments