Skip to content

Commit

Permalink
Propagate install_if and provider_priority to APKINDEX
Browse files Browse the repository at this point in the history
Turn InstallIf into an array as strings (as it has the format as
depend/provides), and add ProviderPriority. Format them into the
geenrated APKINDEX file.

Resolves go-gitea#28704
  • Loading branch information
bugaevc committed Jan 22, 2024
1 parent 4abd63d commit beb75cb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
28 changes: 17 additions & 11 deletions modules/packages/alpine/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ 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"`
}

// ParsePackage parses the Alpine package file
Expand Down Expand Up @@ -179,7 +180,7 @@ func ParsePackageInfo(r io.Reader) (*Package, error) {
case "license":
p.VersionMetadata.License = value
case "install_if":
p.FileMetadata.InstallIf = value
p.FileMetadata.InstallIf = append(p.FileMetadata.InstallIf, value)
case "provides":
if value != "" {
p.FileMetadata.Provides = append(p.FileMetadata.Provides, value)
Expand All @@ -188,6 +189,11 @@ 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
}
}
}
if err := scanner.Err(); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions modules/packages/alpine/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ commit = 1111e709613fbc979651b09ac2bc27c6591a9999
maintainer = ` + packageMaintainer + `
license = MIT
depend = common
install_if = value
install_if = package1=1.40r3
install_if = !bar
depend = gitea
provides = common
provides = gitea`)
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestParsePackage(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, p)

assert.Equal(t, "Q1SRYURM5+uQDqfHSwTnNIOIuuDVQ=", p.FileMetadata.Checksum)
assert.Equal(t, "Q1nExxVXVcTXgbZFLzqlwgJlQELxM=", p.FileMetadata.Checksum)
})
}

Expand Down Expand Up @@ -136,7 +137,7 @@ func TestParsePackageInfo(t *testing.T) {
assert.Equal(t, "aarch64", p.FileMetadata.Architecture)
assert.Equal(t, "origin", p.FileMetadata.Origin)
assert.Equal(t, "1111e709613fbc979651b09ac2bc27c6591a9999", p.FileMetadata.CommitHash)
assert.Equal(t, "value", p.FileMetadata.InstallIf)
assert.Equal(t, []string{"package1=1.40r3", "!bar"}, p.FileMetadata.InstallIf)
assert.ElementsMatch(t, []string{"common", "gitea"}, p.FileMetadata.Provides)
assert.ElementsMatch(t, []string{"common", "gitea"}, p.FileMetadata.Dependencies)
})
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 len(pd.FileMetadata.InstallIf) > 0 {
fmt.Fprintf(&buf, "i:%s\n", strings.Join(pd.FileMetadata.InstallIf, " "))
}
if pd.FileMetadata.ProviderPriority > 0 {
fmt.Fprintf(&buf, "k:%d\n", pd.FileMetadata.ProviderPriority)
}
fmt.Fprint(&buf, "\n")
}

Expand Down

0 comments on commit beb75cb

Please sign in to comment.