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

archive: Add Info() method #69

Closed
wants to merge 2 commits into from

Conversation

woky
Copy link
Contributor

@woky woky commented Jun 21, 2023

At some point we will need to get information about (deb) packages from
(Go) packages other than archive, namely from the slicer package.
For instance:

  • Package entries in Chisel DB will include version, digest and
    architecture.
  • Multi-archive package selection will need to know versions of a
    package in all configured archives.

Add Info() method to the Archive interface that returns a new
PackageInfo interface that contains accessors for the underlying
control.Section of the package. Currently these accessors are Name(),
Version(), Arch() and SHA256() methods.

The reason to introduce PackageInfo interface instead of returing
control.Section directly is keep the archive abstraction and not leak
implementation details.

@woky
Copy link
Contributor Author

woky commented Jun 21, 2023

This PR depends on #80

@woky woky added the Blocked Waiting for something external label Jun 21, 2023
@woky woky force-pushed the pub/archive-package-info branch from 95d7a17 to 107c2b7 Compare June 22, 2023 10:38
@woky woky force-pushed the pub/archive-package-info branch 2 times, most recently from 4c66398 to cbeac7f Compare August 30, 2023 12:04
@woky woky force-pushed the pub/archive-package-info branch 2 times, most recently from e1c21ac to ddd61ef Compare September 19, 2023 06:07
@woky woky force-pushed the pub/archive-package-info branch 8 times, most recently from da096d9 to 5bb81b4 Compare October 9, 2023 19:15
@woky woky added the Priority Look at me first label Oct 12, 2023
@woky
Copy link
Contributor Author

woky commented Oct 12, 2023

This PR can should be reviewed only after #80 is deemed OK.

Currently we only test with the embedded base-files files package. This
quite limits what we can test. But since commit a3315e3
("testutil/pkgdata: Create deb programatically") we have the ability to
define our own custom package content.

Add support for testing with custom packages. These can be defined in
each test case per archive name. The content can be defined directly in
test case definition with the help of testutil.MustMakeDeb().

The package content is wrapped in the testPackage structure. This
introduces one level of nesting in each test case package definition. In
future, we will add package metadata to the package definition, namely
version. So wrapping the package content in the structure now and later
just adding a new field to it the structure later will make the future
diff much smaller.
At some point we will need to get information about (deb) packages from
(Go) packages other than archive, namely from the slicer package.
For instance:
- Package entries in Chisel DB will include version, digest and
  architecture.
- Multi-archive package selection will need to know versions of a
  package in all configured archives.

Add Info() method to the Archive interface that returns a new
PackageInfo interface that contains accessors for the underlying
control.Section of the package. Currently these accessors are Name(),
Version(), Arch() and SHA256() methods.

The reason to introduce PackageInfo interface instead of returing
control.Section directly is keep the archive abstraction and not leak
implementation details.
@niemeyer
Copy link
Contributor

#80 is okay, FWIW.. just one trivial to solve there.

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

This shoud wait for #80 to land, but other than that it looks good, except for the one detail below.

func (info pkgInfo) SHA256() string { return info.Get("SHA256") }

func (a *ubuntuArchive) Info(pkg string) PackageInfo {
if section, _, _ := a.selectPackage(pkg); section != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why drop errors on the floor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just felt that the Info() method (and selectPackage() too) resembles a map read and since it's guaranteed to not hold nil values and will not fail in any expected way (as selectPackage only returns error when it doesn't find an entry in the map), it can just return nil on missing entry.

I understand that this is an interface and so it should be designed for unknown future changes to the implementation, but I assumed that Archive instances are expected to be fully loaded with archive metadata after creation. If e.g. we introduced some lazy loading in future, then even Exists() would have to return error in case lazy loading fails.

Anyway, after #80 gets merged, I'm going to update to return err from selectPackage. Python's dictionaries also fail on KeyError 🤷

@niemeyer niemeyer added the Reviewed Supposedly ready for tuning or merging label Oct 20, 2023
@woky woky removed the Reviewed Supposedly ready for tuning or merging label Oct 23, 2023
@cjdcordeiro cjdcordeiro removed the Priority Look at me first label Oct 26, 2023
@letFunny
Copy link
Collaborator

Per our offline discussion, I think our best way forward is to close this PR and discuss with @rebornplusplus to see if it is a priority right now, and how to amend the code here to make it compatible with the latest changes. We will take that discussion offline and we can always re-open the PRs or create new ones as we see fit.

@cjdcordeiro cjdcordeiro added the Decaying It's been a while, close or act on it label Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked Waiting for something external Decaying It's been a while, close or act on it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants