-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add version collate functions #8168
Add version collate functions #8168
Conversation
Closing and reopening to pick up a test fix from master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think test files will help. You can root around https://github.com/osquery/osquery/pull/6535/files but I don't like the implementation there. (Which is why I never merged it)
By the way, we also have this: https://github.com/osquery/osquery/blob/master/osquery/utils/versioning/semantic.cpp, which is currently unused, so I think we should have one implementation at the end. EDIT: To clarify, if there's no use of code like semantic.cpp (as it's happening now) which extracts the major, minor, patch values from a string, I would just remove it. |
d2a39bb
to
2b8b227
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty clean to me, and reasonably easy to follow. (Sweeeet!)
A couple of suggestions:
- I kinda understand all the boolean options to versionCompare, but I think some comments would help. Some words about why one might want epoch, and how it's used by dpkg. For example...
- If we wanted to expose these as sql functions, and not just collations, how would we? Does it require moving any of the functions around?
- Some docs should land in https://github.com/osquery/osquery/blob/master/docs/wiki/introduction/sql.md which will then appear in https://osquery.readthedocs.io/en/latest/introduction/sql/ Maybe a Collation section?
- Tests are hard to follow, but I'm not sure how to make them better.It is, inherently, a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only a quick stylistic review: can we use std::string_view
instead of const char*
+ length
?
With that, things like strcspn
can be substituted with the string_view method find, which will return the position in the string where the character has been found.
Basically, lets not write C.
The variable names should be snake_case.
Finally, for the switch cases on the ASCII value, instead of the number, can we use the character itself? '~'
etc, so that it's easier to understand which character that corresponds to.
I think that part is driven by the collate api. |
That's the interface, but |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking a bit about tests, I have two observations:
- Everything is testing
true
. I wonder if anything should testfalse
- I wonder if it would be more or less clear to define an array and then sort the whole thing and check the order. Doesn't handle the equality case, but would it be easier to see the order in?
I've switched to using string_views in I went ahead and made the version_compare function, since it looked pretty easy to add that around Added information to the documents, and more comments around the
I felt there wasn't a need to test
I don't quite know what you mean by this. Could you provide an example? |
My inital suggestions have been addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the sql function gets simplified, this is mergable ,
…r vals and branching collation variations
…nality to support the tests
…rsion compare function
…on collations/function
…an true or false for a certain operator
9964283
to
d771b28
Compare
There was a problem hiding this 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 good. @Smjert anything else?
Quality of life improvement. Version strings can be annoying to compare/evaluate since a simple operation can't properly handle numeric values. To work around that I've added a new collation for version comparison.
This works by splitting strings on
.
into segments, then grouping consecutive numeric and alphabetic characters into pieces to compare against. Special characters are dropped, but they continue to split off the grouping. I considered merging those split off groups together, but I feel it would be best to continue splitting off to the next piece instead.This should also be pretty nice on version columns in tables if we add the collation to them.