Skip to content

Add versions to ContentMetadata#986

Merged
HuijingHei merged 4 commits into
coreos:mainfrom
HuijingHei:add-versions
Sep 5, 2025
Merged

Add versions to ContentMetadata#986
HuijingHei merged 4 commits into
coreos:mainfrom
HuijingHei:add-versions

Conversation

@HuijingHei

Copy link
Copy Markdown
Contributor

packagesystem: add struct Module about package name and evr

Also add uapi_version::Version to parse versions according to
Colin's comment #983 (comment)


Add versions to ContentMetadata

Inspired by Colin's comment #977 (comment)
We need versions to save struct like:

  "versions": [
    {"name": "pkg1", "rpm-evr": "1.0"},
    {"name": "pkg2", "rpm-evr": "2.0"}
  ]

Then we read and compare versions, do not need to parse the
version in str format.

Co-worked by walters@verbum.org

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a versions field to ContentMetadata to enable more robust package version comparisons using a structured Module type. This is a valuable improvement over string-based comparison. The implementation is mostly solid, with new logic for parsing and comparing versions, and updated tests.

My review focuses on a couple of correctness issues and a performance improvement. I've identified two places where the newly created Vec<Module> is not sorted before being stored, which violates an assumption made by the comparison function and could lead to incorrect behavior. I've also suggested a more efficient and idiomatic way to handle version comparison logic in ContentMetadata::can_upgrade_to to avoid unnecessary data cloning.

Comment thread src/efi.rs
Comment thread src/packagesystem.rs Outdated
Comment thread src/model.rs Outdated
Comment thread src/packagesystem.rs
});

// Map the version into Module struct
let mut modules_vec: Vec<Module> = pkgs.keys().map(|pkg_str| parse_evr(pkg_str)).collect();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if should map the version str into Module struct when using rpm -q.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hum, I don't understand the question here. Do you mean that if we do rpm -q we should rely on timestamps and not versions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I meant not sure if it is necessary to do the map, and it will compare using version if we do not have the Module struct. But agree to do the map.
Copy the change here:

        if let (Some(self_versions), Some(target_versions)) = (&self.versions, &target.versions) {
            compare_package_slices(self_versions, target_versions)
        } else {
            compare_package_versions(&self.version, &target.version)
        }

@cgwalters cgwalters left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks sane to me!

@HuijingHei

Copy link
Copy Markdown
Contributor Author

Rebase the main branch to include CI workflow fix, and will fix the CI failed.

Also add `uapi_version::Version` to parse versions according to
Colin's comment coreos#983 (comment)
Inspired by Colin's comment coreos#977 (comment)
We need `versions` to save struct like:
```
  "versions": [
    {"name": "pkg1", "rpm-evr": "1.0"},
    {"name": "pkg2", "rpm-evr": "2.0"}
  ]
```
Then we read and compare versions, do not need to parse the
version in str format.

Co-worked by walters@verbum.org
@HuijingHei

Copy link
Copy Markdown
Contributor Author

Rebase to main branch and update test, and will merge this as the CI is passed.

@travier travier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I'm afraid that if we get a source package name that includes a "-" that we will not get the name properly recognized but we can probably worry about that if that happens. Neither grub2, shim, not systemd-boot (systemd source package name) are in this case.

Comment thread src/bootupd.rs
@HuijingHei
HuijingHei merged commit a100398 into coreos:main Sep 5, 2025
12 checks passed
@HuijingHei
HuijingHei deleted the add-versions branch September 5, 2025 12:03
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.

4 participants