Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DownloadDir for chroot #89

Open
sfuerte opened this issue Nov 12, 2021 · 1 comment
Open

Implement DownloadDir for chroot #89

sfuerte opened this issue Nov 12, 2021 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@sfuerte
Copy link

sfuerte commented Nov 12, 2021

Community Note

Please vote on this issue by adding a 馃憤 reaction 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
}
@nywilken
Copy link
Member

Hi @sfuerte this sounds like a good idea. We probably wont be able to get to this right now but, since you've started to look through the code we would be happy to review a PR if you want to make the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants