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

(FACT-1246) Return the first value found in ID_LIKE #1226

Merged
merged 1 commit into from
Nov 20, 2015
Merged

(FACT-1246) Return the first value found in ID_LIKE #1226

merged 1 commit into from
Nov 20, 2015

Conversation

ScottGarman
Copy link

The ID_LIKE field may contain a space-separated list of related OS
families. Some Cisco platforms exercise this feature, and when they
do so, we only want to return the first value found.

Tested on the cisco-wrlinux-7 platform with the following release file contents:

/etc/os-release:
ID=wrlinux
NAME=Wind River Linux
VERSION=7.0.0.2
VERSION_ID=7.0.0.2
PRETTY_NAME=Wind River Linux 7.0.0.2
CISCO_RELEASE_INFO=/etc/cisco-release

/etc/cisco-release:
ID=ios_xr
ID_LIKE="cisco-wrlinux wrlinux"
NAME=IOS XR
VERSION="6.0.0.20I"
VERSION_ID=6.0.0.20I
PRETTY_NAME="Cisco IOS XR Software, Version 6.0.0.20I"
HOME_URL=http://www.cisco.com
BUILD_ID="2015-10-22-18-52-49"
CISCO_RELEASE_INFO=/etc/cisco-release

This is the first time I've touched C++ code in years, so please be thorough when explaining any desired refactorings.

@mcdonaldseanp
Copy link

👍 Everything looks good to me

@peterhuene
Copy link

👍 @kylog should we adopt this for the next sprint?

@@ -57,7 +57,17 @@ namespace facter { namespace facts { namespace linux {
return value;
}
auto val = _release_info.find("ID_LIKE");
return (val != _release_info.end()) ? val->second : std::string();
if (val != _release_info.end()) {
auto family = val->second;

Choose a reason for hiding this comment

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

Nit pick: this makes a copy of the string, which is fine when it doesn't contain a space (we were copying it when returning it anyway), but in the case where it does contain a space, the copy doesn't need to be made.

Using auto& family = val->second; (note the &) creates a reference to the value, which we'll only copy if it doesn't contain a space.

@peterhuene
Copy link

Other than the above nit picks, this looks good to merge to me.

The ID_LIKE field may contain a space-separated list of related OS
families. Some Cisco platforms exercise this feature, and when they
do so, we only want to return the first value found.
@ScottGarman
Copy link
Author

@peterhuene thanks for the review - I've made changes to the code based on your feedback. Should be good to go now.

peterhuene added a commit that referenced this pull request Nov 20, 2015
(FACT-1246) Return the first value found in ID_LIKE
@peterhuene peterhuene merged commit 34977ae into puppetlabs:master Nov 20, 2015
@glennmatthews
Copy link

👍 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants