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

config/module: use the raw source as part of the key #9144

Merged
merged 1 commit into from
Oct 11, 2016
Merged

Conversation

mitchellh
Copy link
Contributor

Fixes customer ticket 1806.

This changes the key for the storage to be the raw source from the
module, not the fully expanded source. Example: it'll be a relative path
instead of an absolute path.

This allows the ".terraform/modules" directory to be portable when
moving to other machines. This was a behavior that existed in <= 0.7.2
and was broken with #8398. This amends that and adds a test to verify.

This changes the key for the storage to be the _raw_ source from the
module, not the fully expanded source. Example: it'll be a relative path
instead of an absolute path.

This allows the ".terraform/modules" directory to be portable when
moving to other machines. This was a behavior that existed in <= 0.7.2
and was broken with #8398. This amends that and adds a test to verify.

entry, err = os.Stat(target)
if err != nil {
return err
Copy link
Member

@jbardin jbardin Sep 30, 2016

Choose a reason for hiding this comment

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

Here's a prime example of having to be very careful with naked returns and name result parameters, since err was shadowed in this for loop. This is handled correctly here, but the mix of return values and naked returns in this code looks prime for introducing bugs later on. Can we drop the named result value for this function?

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 just copied this code from the gist at the top of the file. It isn't tested since it itself is only used in tests and the original source didn't come with it. I can add it if we want but I agree there is a LOT stylistically I disagree with in this code but it was a copy pasta.

}
defer func() {
if e := out.Close(); e != nil {
err = e
Copy link
Member

@jbardin jbardin Sep 30, 2016

Choose a reason for hiding this comment

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

You should check if err == nil before assigning e here, since an existing error is probably more important that the Close error.

if err != nil && !os.IsNotExist(err) {
return
}
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

passing a nil error to os.IsNotExist returns false, so you could just do a single check. Any other errors will be caught later anyway

    if !os.IsNotExist(err) {
        return fmt.Errorf("destination already exists")
    }

(only mention it because the err == nil check threw me for a second)

Copy link
Member

@jbardin jbardin left a comment

Choose a reason for hiding this comment

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

Since this is just a helper for a unit tests, and none of the issue are fatal, we can rewrite the copy functions at our leisure.

@jbardin jbardin merged commit 404a76e into master Oct 11, 2016
@mitchellh mitchellh deleted the b-source branch October 12, 2016 16:30
@ghost
Copy link

ghost commented Apr 21, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 21, 2020
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.

3 participants