hashicorp / hashicorp/packer-plugin-sdk

Implement DownloadDir for chroot

Open
#89 1 comment 2 reactions 0 assignees View on GitHub
enhancement good first issue help wanted
Dominant language
Go
Stars
42
Forks
62
Avg merge
29m
Merged PRs (30d)
2

Description

#### Community Note

Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request.
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.

#### Description

At the moment, `chroot` simply fails with `DownloadDir is not implemented for amazon-chroot`, which is an artifact from the past.
https://github.com/hashicorp/packer-plugin-sdk/blob/main/chroot/communicator.go#L126

The implementation can be easily done with reversing `UploadDir` defined above in the same file:
```
func (c *Communicator) DownloadDir(src string, dst string, exclude []string) error {
// If src ends with a trailing "/", copy from "src/." so that
// directory contents (including hidden files) are copied, but the
// directory "src" is omitted. BSD does this automatically when
// the source contains a trailing slash, but linux does not.
if src[len(src)-1] == '/' {
src = src + "."
}

// TODO: remove any file copied if it appears in `exclude`
chrootSrc := filepath.Join(c.Chroot, src)
log.Printf("Downloading directory '%s' to '%s'", chrootSrc, dst)

cmd, err := c.CmdWrapper(fmt.Sprintf("cp -R '%s' %s", chrootSrc, dst))
if err != nil {
return err
}

stderr := new(bytes.Buffer)
shell := common.ShellCommand(cmd)
shell.Env = append(shell.Env, "LANG=C")
shell.Env = append(shell.Env, os.Environ()...)
shell.Stderr = stderr
if err := shell.Run(); err == nil {
return err
}

if strings.Contains(stderr.String(), "No such file") {
// This just means that the directory was empty. Just ignore it.
return nil
}

return err
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.