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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude #18

Merged
merged 8 commits into from
Apr 24, 2018
Merged

Exclude #18

merged 8 commits into from
Apr 24, 2018

Conversation

raymondhardynike
Copy link
Contributor

This allows a user to exclude files when using dir archive.

@catsby catsby requested a review from paultyng April 5, 2018 20:58
Copy link

@catsby catsby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit, but I'd like @paultyng to review as well, I think he may have more context/experience here than I do

@Constantin07
Copy link

I also need to exclude some files from directory before zipping it.
Any idea when this PR will be approved ?

Copy link
Contributor

@paultyng paultyng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great addition, but I wonder if this really needs to be a TypeList if its also a regexp? Can't you just a|b|c?

May be simpler to just flatten this to a TypeString and use the regexp validation: https://github.com/hashicorp/terraform/blob/2dc7241df0245b2be005946b4bc903dfab496c71/helper/validation/validation.go#L254-L259

If you would prefer to use a list of strings I'd rather drop the regexp support then and just use explicit relative path names for exclusion. That would also simplify a lot of the checking logic and remove some of the regexp magic with the appending of the anchors.

data "archive_file" "foo" {
type = "zip"
source_dir = "../archive/test-fixtures/../test-fixtures/test-dir"
excludes = ["test-fixtures/test-dir/file2.txt"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some whitespace weirdness in here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can fix this

@@ -83,12 +98,25 @@ func (a *ZipArchiver) ArchiveDir(indirname string) error {
defer a.close()

return filepath.Walk(indirname, func(path string, info os.FileInfo, err error) error {
tmpFilePath, _ := filepath.Abs(path)
tmpLongFileName, _ := filepath.Abs(indirname)
shortFileName := strings.TrimPrefix(tmpFilePath, tmpLongFileName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use filepath.Rel (it's already used below, you could just move that line up)

Copy link
Contributor Author

@raymondhardynike raymondhardynike Apr 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will test this

if info.IsDir() {
if isMatch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you probably still want to walk all the dirs and match against the full relative paths? You may want to add a test case that covers this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you match on a directory you are excluding the directory why match after that?

i.e.
/hi/
/hello/world
/hello/i/am/here
if you exclude hello/ you should exclude everything in the hello path why still walk?

@raymondhardynike
Copy link
Contributor Author

I have updated this to use relative path for exact match removing globing on anything except dirs.

Copy link
Contributor

@paultyng paultyng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, just one minor thing to prevent spurious diff.

@@ -77,6 +77,15 @@ func dataSourceFile() *schema.Resource {
ForceNew: true,
ConflictsWith: []string{"source_content", "source_content_filename", "source_file"},
},
"excludes": &schema.Schema{
Type: schema.TypeList,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a TypeSet as it's order does not matter I think? https://www.terraform.io/docs/extend/schemas/schema-types.html#typeset

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah typeSet works

@paultyng paultyng merged commit 1131a8b into hashicorp:master Apr 24, 2018
@raymondhardynike raymondhardynike deleted the exclude branch April 24, 2018 16:12
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants