Skip to content

Propagate install_if and provider_priority to APKINDEX #28899

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

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions modules/packages/alpine/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@ type VersionMetadata struct {
}

type FileMetadata struct {
Checksum string `json:"checksum"`
Packager string `json:"packager,omitempty"`
BuildDate int64 `json:"build_date,omitempty"`
Size int64 `json:"size,omitempty"`
Architecture string `json:"architecture,omitempty"`
Origin string `json:"origin,omitempty"`
CommitHash string `json:"commit_hash,omitempty"`
InstallIf string `json:"install_if,omitempty"`
Provides []string `json:"provides,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Checksum string `json:"checksum"`
Packager string `json:"packager,omitempty"`
BuildDate int64 `json:"build_date,omitempty"`
Size int64 `json:"size,omitempty"`
Architecture string `json:"architecture,omitempty"`
Origin string `json:"origin,omitempty"`
CommitHash string `json:"commit_hash,omitempty"`
InstallIf string `json:"install_if,omitempty"`
Provides []string `json:"provides,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
ProviderPriority int64 `json:"provider_priority,omitempty"`
ReplacesPriority int64 `json:"replaces_priority,omitempty"`
}

// ParsePackage parses the Alpine package file
Expand Down Expand Up @@ -188,6 +190,16 @@ func ParsePackageInfo(r io.Reader) (*Package, error) {
if value != "" {
p.FileMetadata.Dependencies = append(p.FileMetadata.Dependencies, value)
}
case "provider_priority":
n, err := strconv.ParseInt(value, 10, 64)
if err == nil {
p.FileMetadata.ProviderPriority = n
}
case "replaces_priority":
n, err := strconv.ParseInt(value, 10, 64)
if err == nil {
p.FileMetadata.ReplacesPriority = n
Copy link
Member

Choose a reason for hiding this comment

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

Did I miss something, or is the ReplacesPriority currently unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is unused indeed. It is a part of Alpine package metadata, so it makes sense to parse and store it alongside all the other package metadata, but there isn't anything else being done with it currently. Specifically, it looks like there's no field for replaces_priority in the APKINDEX file, so ReplacesPriority is not used when generating APKINDEX.

I guess ReplacesPriority could show up in some HTTP API request if there is one that returns package file metadata, or if one is added in the future.

Copy link
Member

Choose a reason for hiding this comment

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

In that case, I recommend adding a comment to the field stating exactly that.

Copy link
Member

Choose a reason for hiding this comment

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

I removed the field as it's not used in the index spec at the moment. We can add it if it is used in future.

https://wiki.alpinelinux.org/wiki/Apk_spec#APKINDEX_Format

}
}
}
if err := scanner.Err(); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions services/packages/alpine/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ func buildPackagesIndex(ctx context.Context, ownerID int64, repoVersion *package
if len(pd.FileMetadata.Provides) > 0 {
fmt.Fprintf(&buf, "p:%s\n", strings.Join(pd.FileMetadata.Provides, " "))
}
if pd.FileMetadata.InstallIf != "" {
fmt.Fprintf(&buf, "i:%s\n", pd.FileMetadata.InstallIf)
}
if pd.FileMetadata.ProviderPriority > 0 {
fmt.Fprintf(&buf, "k:%d\n", pd.FileMetadata.ProviderPriority)
}
fmt.Fprint(&buf, "\n")
}

Expand Down