Skip to content

Commit

Permalink
Fix fetching artifacts when sudo -i changes directory
Browse files Browse the repository at this point in the history
When spread connects to a machine as a non-root user, then it injects calls to
sudo -i to run commands as root. This effectively makes the artifact sending
logic is basically:

```sh
cd directory
sudo -i tar ...
```

The problem is that sudo -i changes the current working directory back to
/root. Pass -C or --directory= to tar, so that all the files are referenced
relative to the task directory.

Signed-off-by: Zygmunt Krynicki <[email protected]>
  • Loading branch information
zyga committed Dec 3, 2024
1 parent ded9133 commit 9fcda79
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion spread/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ func (c *Client) RecvTar(packDir string, include []string, tar io.Writer) error
var stderr safeBuffer
session.Stdout = tar
session.Stderr = &stderr
cmd := fmt.Sprintf(`cd '%s' && %s/bin/tar cJ --sort=name --ignore-failed-read -- %s`, packDir, c.sudo(), strings.Join(args, " "))
cmd := fmt.Sprintf(`%s/bin/tar -C %q -cJ --sort=name --ignore-failed-read -- %s`, c.sudo(), packDir, strings.Join(args, " "))
err = c.runCommand(session, cmd, nil, &stderr)
if err != nil {
return outputErr(stderr.Bytes(), err)
Expand Down

0 comments on commit 9fcda79

Please sign in to comment.