Skip to content

store: Add accessors for the ostree repo #1509

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cgwalters
Copy link
Collaborator

To make clearer what it is vs the other two storage types.

In practice of course most acccesses to this are via the Deref, but that's a much bigger patch that will be a followup to this.

To make clearer what it is vs the other two storage types.

In practice of course *most* acccesses to this are
via the Deref, but that's a much bigger patch that
will be a followup to this.

Signed-off-by: Colin Walters <[email protected]>
Copy link
Contributor

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

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 refactors the Storage struct by renaming the sysroot field to ostree and introducing accessor methods for it. This improves encapsulation and clarity. The changes are applied consistently across the codebase.

I have one suggestion to further improve the new accessor methods by simplifying their signatures, which would make them more idiomatic and easier to use.

Comment on lines +127 to +136
/// Access the underlying ostree repository
pub(crate) fn get_ostree(&self) -> Result<&SysrootLock> {
Ok(&self.ostree)
}

/// Access the underlying ostree repository
pub(crate) fn get_ostree_cloned(&self) -> Result<ostree::Sysroot> {
let r = self.get_ostree()?;
Ok((*r).clone())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

These accessor functions can be simplified. Since neither get_ostree nor get_ostree_cloned can fail in their current implementation, they shouldn't return a Result.

Additionally, (*r).clone() in get_ostree_cloned is a bit confusing. It can be simplified to self.get_ostree().clone() after changing get_ostree's signature.

This change would make the API cleaner and more idiomatic, and simplify call sites by removing unnecessary ? operators.

    /// Access the underlying ostree repository
    pub(crate) fn get_ostree(&self) -> &SysrootLock {
        &self.ostree
    }

    /// Access the underlying ostree repository
    pub(crate) fn get_ostree_cloned(&self) -> ostree::Sysroot {
        self.get_ostree().clone()
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes the use of Result is intentional here because I want to change it to be a fallible operation in the future.

@bshephar
Copy link

It will definitely get a bit wild in deploy.rs once the composefs work is merged from:
https://github.com/bootc-dev/bootc/pull/1444/files

The nomenclature update is helpful for that, but maybe this file can be broken up a bit with some methods specific to their backend living in their own files?

@@ -42,7 +42,7 @@ pub(crate) struct Storage {
pub physical_root: Dir,

/// The OSTree storage
pub sysroot: SysrootLock,
ostree: SysrootLock,

Choose a reason for hiding this comment

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

Right, the change in scope here was indeed intentional because your helper functions here are now doing the cloning, rather than having them cloned in deploy.rs, I see.

@cgwalters
Copy link
Collaborator Author

It will definitely get a bit wild in deploy.rs once the composefs work is merged from:
https://github.com/bootc-dev/bootc/pull/1444/files

Yes this is preparatory work for that.

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.

2 participants