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

Caret comparison #65

Merged
merged 2 commits into from
Jul 12, 2023
Merged

Caret comparison #65

merged 2 commits into from
Jul 12, 2023

Conversation

behrmann
Copy link
Member

Looking at the reference implementation in systemd-analyze compare-versions the code handling the caret character is the same as for - and ., right before and after:

        /* Handle '-', which separates version and release, e.g 123.4-3.1.fc33.x86_64 */
        if (*a == '-' || *b == '-') {
                /* The string prefixed with '-' is older (e.g., 123-9 vs 123.1-1) */
                r = CMP(*a != '-', *b != '-');
                if (r != 0)
                        return r;

                a++;
                b++;
        }

        /* Handle '^'. Used for patched release. */
        if (*a == '^' || *b == '^') {
                r = CMP(*a != '^', *b != '^');
                if (r != 0)
                        return r;

                a++;
                b++;
        }

        /* Handle '.'. Used for point releases. */
        if (*a == '.' || *b == '.') {
                r = CMP(*a != '.', *b != '.');
                if (r != 0)
                        return r;

                a++;
                b++;
        }

so the caret character must be treated the same in the spec as well. This is not a bug in the reference implementation, since when the sign of the comparison is inverted, i.e. caret compares higher than not-caret, the comparison

  • 123^post1 < 123.a-1

would not hold true anymore, since ^ would win against . at step 5. This comparison must hold true, to be compatible with rpmdev-vercmp

Note: rpmdev-vercmp does compare 123^post1 < 123.a-1, but compares ^ > ., which systemd-analyze compares ^ < .

This PR also adds an extended example taken from a comment of the function implementing this in systemd-analyze, which I found helpful.

Looking at the reference implementation in "systemd-analyze compare-versions"
the code handling the caret character is the same as for "-" and ".", right
before and after:

        /* Handle '-', which separates version and release, e.g 123.4-3.1.fc33.x86_64 */
        if (*a == '-' || *b == '-') {
                /* The string prefixed with '-' is older (e.g., 123-9 vs 123.1-1) */
                r = CMP(*a != '-', *b != '-');
                if (r != 0)
                        return r;

                a++;
                b++;
        }

        /* Handle '^'. Used for patched release. */
        if (*a == '^' || *b == '^') {
                r = CMP(*a != '^', *b != '^');
                if (r != 0)
                        return r;

                a++;
                b++;
        }

        /* Handle '.'. Used for point releases. */
        if (*a == '.' || *b == '.') {
                r = CMP(*a != '.', *b != '.');
                if (r != 0)
                        return r;

                a++;
                b++;
        }

so the caret character must be treated the same in the spec as well. This is not
a bug in the reference implementation, since when the sign of the comparison is
inverted, i.e. caret compares higher than not-caret, the comparison

        123^post1 < 123.a-1

would *not* hold true anymore, since "^" would win against "." at step 5. This
comparison must hold true, to be compatible with rpmdev-vercmp

Note: rpmdev-vercmp does compare 123^post1 < 123.a-1, but compares ^ > ., which
      systemd-analyze compares ^ < .
This example is taken from systemd/src/fundamental/string-util-fundamental.c
@bluca bluca merged commit 5a0799d into uapi-group:main Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants