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

Fix alternate path profile chaining #2121

Merged
merged 1 commit into from
Sep 6, 2017

Conversation

trevor-vaughan
Copy link
Contributor

Update to fix how multiple relative profile chaining functions.

Closes #2120

@trevor-vaughan trevor-vaughan requested a review from a team as a code owner September 4, 2017 22:29
@trevor-vaughan trevor-vaughan force-pushed the deep_profile_chaining_fix branch 3 times, most recently from 5f0ef4b to 0f22468 Compare September 5, 2017 02:28
@trevor-vaughan trevor-vaughan changed the title Fix deep profile chaining Fix alternate path profile chaining Sep 5, 2017
Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @trevor-vaughan! Unfortunately I don't think it will work for absolute paths in dependencies. I've left you a comment with a potential alternate solution that you should test to see if it meets the needs of the issue you're trying to solve. Thanks!

req_path = opts[:cwd]

if dep[:path]
req_path = File.join(req_path, dep[:path])
Copy link
Contributor

@adamleff adamleff Sep 5, 2017

Choose a reason for hiding this comment

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

I think this will only work if the path in the requirement is a relative path. What if I have an absolute path in my metadata?

depends:
  - name: foo
    path: '/path/to/foo'

If my cwd is /home/aleff/profiles, this would set the req_path to /home/aleff/profiles/path/to/foo which won't exist... correct?

You probably want to look into using File.expand_path here instead which handles both relative and absolute path expansion.

[1] pry(main)> Dir.pwd
=> "/Users/aleff/profiles/test1"
[2] pry(main)> File.expand_path('../test2', Dir.pwd)
=> "/Users/aleff/profiles/test2"
[3] pry(main)> File.expand_path('/opt/chef/embedded', Dir.pwd)
=> "/opt/chef/embedded"

@adamleff adamleff added the Type: Bug Feature not working as expected label Sep 5, 2017
@trevor-vaughan trevor-vaughan force-pushed the deep_profile_chaining_fix branch from aeb65ca to f0ec079 Compare September 5, 2017 19:36
@trevor-vaughan
Copy link
Contributor Author

@adamleff Good call. Fixed

new(dep[:name],
dep[:version],
cache,
File.absolute_path(req_path),
Copy link
Contributor

Choose a reason for hiding this comment

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

File.expand_path here should do the trick, right? We probably don't even need to call on File.absolute_path anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh, completely missed that. Updated.

Update to fix how multiple relative profile chaining functions.

Closes inspec#2120

Signed-off-by: Trevor Vaughan <[email protected]>
@trevor-vaughan trevor-vaughan force-pushed the deep_profile_chaining_fix branch from f0ec079 to 875831d Compare September 5, 2017 19:54
Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

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

This looks good to me, @trevor-vaughan, thanks!

In the future, we prefer it if you don't rebase/amend your commits each time as it helps us look at only the stuff that's changed between reviews. While it's not as big of a deal on this change since it's so small, it helps reduce the amount of time spent reviewing the PR on larger changes.

Thanks again for your contribution!

@adamleff adamleff requested a review from a team September 5, 2017 19:58
@trevor-vaughan
Copy link
Contributor Author

@adamleff Got it, I'll keep that in mind in the future.

Copy link
Contributor

@arlimus arlimus left a comment

Choose a reason for hiding this comment

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

Awesome catch and bugfix, thank you Trevor!! 😁

@arlimus arlimus merged commit fb011c1 into inspec:master Sep 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chained InSpec Profiles use the wrong base path
3 participants