Closed exincore closed 2 years ago
Instead of fuzzy matching, looking at ID
(and ID_LIKE
) likely works better than NAME
for parsing.
I'll go ahead and fork and see if I can take a swing at improving refactoring get_type
slightly significantly. Currently I am was looking at accumulating all the detected *-release
files together, then regex capturing for ID
. If that fails it will fallback to the DISTRIBUTIONS
method as that presumably covers older cases before os-release
became mainstream or if there are some other distribution quirks.
I found a resource for the os-release files to cross reference with what ID
fields I know: https://github.com/chef/os_release
Thank you for the very detailed bug report! And sorry for the late reply - I have recently changed a job, so not it takes most of my free time. I see you drafted the pull request and will try to look into it.
I believe I have found how this module has been falsely identifying so many operating systems as OracleLinux. See:
301
275
Failure Mode
linux/mod.rs
is runlsb_release
is not installed and fails properly;linux/mod.rs
falls back tofile_release
DISTRIBUTIONS
,file_release
will initially attempt to read a{mariner,centos,fedora,alpine}-release
, each of which fail properly to the next in the array since those files do not exist in this scenario.file_release
arrives atos-release
with a fallback Type asOracleLinux
as defined inDISTRIBUTIONS
. Theos-release
file DOES exist and a parsing attempt is made.Matcher::KeyValue
searches for "NAME"get_type
function attempts to convert the identified name string into aType
, but fails to match due to not being robust enough: lacking any sort of fuzzy matching or regex, the NAME field not existing, or having a limited list of potential matches.None
returned byget_type
,file_release
uses the fallback TypeOracleLinux
from the current array element, and proceeds to identify the version as it would any otheros-release
.Type
andVersion
in hand,file_release
returns, short-circuiting any other array elements defined inDISTRIBUTIONS
as long asos-release
exists.Type
ofOracleLinux
is returned, whileVersion
is correct as it is specific toos-release
and not the returnedOracleLinux
.Notes
DISTRIBUTIONS
array but instead skip to using the known correct element, therefore the tests for the 6th elementRedHatEnterprise
cannot uncover the short-circuit caused by the 5th element,OracleLinux
.os-release
, theID
field is much more stable thanNAME
and is designed to be more script-friendly.Type
ofLinux
from ever being returned as long asos-release
exists. That is, many Linux distributions that this module cannot identify specifically, and should fallback to justLinux
, will instead be identified asOracleLinux
as long asos-release
exists on the distribution.file_release
, so iflsb_release
is not installed, Gentoo will always be identified asOracleLinux
. Though, Gentoo has its own specificgentoo-release
file that should be checked by this crate anyway.