From bc0845b10ec602a80c0b5d0d725b15b50ce7e660 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 29 Oct 2024 09:04:11 +0000 Subject: [PATCH] Return pointer rather than instance on read of PackageRevision from db --- pkg/db/dbpackagerevisionsql.go | 6 +++--- pkg/db/dbrepository.go | 2 +- pkg/registry/porch/name.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/db/dbpackagerevisionsql.go b/pkg/db/dbpackagerevisionsql.go index e63fdc40..ca7e8d18 100644 --- a/pkg/db/dbpackagerevisionsql.go +++ b/pkg/db/dbpackagerevisionsql.go @@ -61,10 +61,10 @@ func pkgRevReadFromDB(prk repository.PackageRevisionKey) (dbPackageRevision, err return dbPkgRev, err } -func pkgRevReadPRsFromDB(pk repository.PackageKey) ([]dbPackageRevision, error) { +func pkgRevReadPRsFromDB(pk repository.PackageKey) ([]*dbPackageRevision, error) { sqlStatement := `SELECT * FROM package_revisions WHERE namespace=$1 AND repo_name=$2 AND package_name=$3` - var dbPkgRevs []dbPackageRevision + var dbPkgRevs []*dbPackageRevision klog.Infof("pkgReadPRsFromDB: running query [%q] on %q", sqlStatement, pk) @@ -98,7 +98,7 @@ func pkgRevReadPRsFromDB(pk repository.PackageKey) ([]dbPackageRevision, error) klog.Infof("pkgRevReadFromDB: reading package revision resources %q returned err: %q", pkgRev.Key(), err) } - dbPkgRevs = append(dbPkgRevs, pkgRev) + dbPkgRevs = append(dbPkgRevs, &pkgRev) } return dbPkgRevs, nil diff --git a/pkg/db/dbrepository.go b/pkg/db/dbrepository.go index fef5154f..678db8be 100644 --- a/pkg/db/dbrepository.go +++ b/pkg/db/dbrepository.go @@ -81,7 +81,7 @@ func (r dbRepository) ListPackageRevisions(ctx context.Context, filter repositor return nil, err } - var foundPkgRevs []dbPackageRevision + var foundPkgRevs []*dbPackageRevision for _, pkg := range pkgs { pkgRevs, err := pkgRevReadPRsFromDB(pkg.Key()) diff --git a/pkg/registry/porch/name.go b/pkg/registry/porch/name.go index ded6eba6..9a245309 100644 --- a/pkg/registry/porch/name.go +++ b/pkg/registry/porch/name.go @@ -23,10 +23,10 @@ func ParseRepositoryName(name string) (string, error) { if strings.Contains(name, ".") { // New type of parseable package revision name parsedName := strings.Split(name, ".") - if len(parsedName) != 5 { - return "", fmt.Errorf("malformed package revision name; expected five elements delimited by \".\" characters: %q", name) + if len(parsedName) != 4 { + return "", fmt.Errorf("malformed package revision name; expected 4 elements delimited by \".\" characters: %q", name) } - return parsedName[1], nil + return parsedName[0], nil } else { // Old type of package revision name lastDash := strings.LastIndex(name, "-")