Skip to content

Commit

Permalink
Fix fetching artifacts when sudo changes directory
Browse files Browse the repository at this point in the history
The artifact sending logic is basically:

```sh
cd directory
sudo tar ...
```

The problem is that sudo may have done something that changes the directory.
I've observed this while testing on Ubuntu 24.10. Instead of fiddling with more
fringe options around sudo, 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 Nov 29, 2024
1 parent ded9133 commit 8c4bd38
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 8c4bd38

Please sign in to comment.