hashicorp / hashicorp/packer

File provisioner incorrectly embeds source/ directory into dest when downloading

Open
#12,193 2 comments 0 reactions 0 assignees View on GitHub
bug provisioner/file
Dominant language
Go
Stars
15.8k
Forks
3.3k
PR merge metrics
PR metrics pending

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 other comments that do not add relevant new information or questions, 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

#### Overview of the Issue

File provisioner appears to embed source directory within destination when source directotory is specified with a trailing slash, and *direction* is *download*, contrary to the docs.

The issue appears to only be present when `direction = "download"`. When uploading, it works as documented.

#### Reproduction Steps

```hcl
provisioner "file" {
direction = "download"
source = "~/source/"
destination = "./dest"
}
```
results in downloading files under `./dest/source/`, instead of under `./dest/` as specified in [documentation](https://developer.hashicorp.com/packer/docs/provisioners/file#directory-uploads).

Result is the same whether or not destination includes a trailing slash.

### Packer version

`Packer v1.8.3` (slightly out of date, but I couldn't find any related bug report so haven't tried updating).

### Operating system and Environment details

Both source and destination systems run Ubuntu 22.04.

Contributor guide

Open the contributing guide

Research direction

Start with Packer's file provisioner download path and reproduce the configuration from the issue on Ubuntu. Compare the result with the linked directory-upload documentation; the work is done when a source directory with a trailing slash downloads its contents directly under the destination without adding the source directory name.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.