Skip to content

Commit 6fc14fb

Browse files
Rework types a little
1 parent ac1b8a8 commit 6fc14fb

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

pkg/apk/apk/implementation.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,10 @@ func (a *APK) InstallPackages(ctx context.Context, sourceDateEpoch *time.Time, a
786786
if err != nil {
787787
return fmt.Errorf("failed to read .PKGINFO for %s: %w", pkg, err)
788788
}
789-
infos[i] = pkgInfo
789+
asPackage := pkgInfo.AsPackage(exp.ControlHash, uint64(exp.Size))
790+
infos[i] = &asPackage
790791

791-
installedFiles, err := a.installPackage(ctx, pkgInfo, exp, sourceDateEpoch)
792+
installedFiles, err := a.installPackage(ctx, &asPackage, exp, sourceDateEpoch)
792793
if err != nil {
793794
return fmt.Errorf("installing %s: %w", pkg, err)
794795
}

pkg/apk/expandapk/expandapk.go

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"path/filepath"
2222
"strings"
2323
"sync"
24-
"time"
2524

2625
"chainguard.dev/apko/internal/tarfs"
2726
"chainguard.dev/apko/pkg/apk/types"
@@ -104,12 +103,12 @@ type APKExpanded struct {
104103
SignatureSize int64
105104

106105
sync.Mutex
107-
parsedPkgInfo *types.Package
106+
parsedPkgInfo *types.PackageInfo
108107
controlData []byte
109108
}
110109

111110
// PkgInfo parses and returns the .PKGINFO file.
112-
func (a *APKExpanded) PkgInfo() (*types.Package, error) {
111+
func (a *APKExpanded) PkgInfo() (*types.PackageInfo, error) {
113112
a.Lock()
114113
defer a.Unlock()
115114
if a.parsedPkgInfo != nil {
@@ -127,31 +126,7 @@ func (a *APKExpanded) PkgInfo() (*types.Package, error) {
127126
return nil, fmt.Errorf("parsing .PKGINFO: %w", err)
128127
}
129128

130-
pkg := &types.Package{
131-
Name: pkginfo.Name,
132-
Version: pkginfo.Version,
133-
Arch: pkginfo.Arch,
134-
Description: pkginfo.Description,
135-
License: pkginfo.License,
136-
Origin: pkginfo.Origin,
137-
Maintainer: pkginfo.Maintainer,
138-
URL: pkginfo.URL,
139-
Checksum: a.ControlHash,
140-
Dependencies: pkginfo.Dependencies,
141-
Provides: pkginfo.Provides,
142-
InstallIf: pkginfo.InstallIf,
143-
Size: uint64(a.Size),
144-
InstalledSize: pkginfo.Size,
145-
ProviderPriority: pkginfo.ProviderPriority,
146-
BuildTime: time.Unix(pkginfo.BuildDate, 0).UTC(),
147-
BuildDate: pkginfo.BuildDate,
148-
RepoCommit: pkginfo.RepoCommit,
149-
Replaces: pkginfo.Replaces,
150-
DataHash: pkginfo.DataHash,
151-
Triggers: pkginfo.Triggers,
152-
}
153-
154-
a.parsedPkgInfo = pkg
129+
a.parsedPkgInfo = pkginfo
155130
return a.parsedPkgInfo, nil
156131
}
157132

pkg/apk/types/package.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,34 @@ type PackageInfo struct {
3131
Triggers []string `ini:"triggers,,allowshadow"`
3232
}
3333

34+
// AsPackage converts PackageInfo to a Package struct with the given controlHash and size.
35+
func (pkginfo *PackageInfo) AsPackage(controlHash []byte, size uint64) Package {
36+
return Package{
37+
Name: pkginfo.Name,
38+
Version: pkginfo.Version,
39+
Arch: pkginfo.Arch,
40+
Description: pkginfo.Description,
41+
License: pkginfo.License,
42+
Origin: pkginfo.Origin,
43+
Maintainer: pkginfo.Maintainer,
44+
URL: pkginfo.URL,
45+
Dependencies: pkginfo.Dependencies,
46+
Provides: pkginfo.Provides,
47+
InstallIf: pkginfo.InstallIf,
48+
InstalledSize: pkginfo.Size,
49+
ProviderPriority: pkginfo.ProviderPriority,
50+
BuildDate: pkginfo.BuildDate,
51+
RepoCommit: pkginfo.RepoCommit,
52+
Replaces: pkginfo.Replaces,
53+
DataHash: pkginfo.DataHash,
54+
Triggers: pkginfo.Triggers,
55+
56+
BuildTime: time.Unix(pkginfo.BuildDate, 0).UTC(),
57+
Checksum: controlHash,
58+
Size: uint64(size),
59+
}
60+
}
61+
3462
// Package represents a single package with the information present in an
3563
// APKINDEX.
3664
type Package struct {

0 commit comments

Comments
 (0)