summaryrefslogtreecommitdiffstats
path: root/models/packages
diff options
context:
space:
mode:
authorYarden Shoham <git@yardenshoham.com>2023-04-29 01:06:41 +0300
committerGitHub <noreply@github.com>2023-04-28 18:06:41 -0400
commitc0ddec8a2a4cd348462257e0ceb253daf5692c32 (patch)
tree6fd2e68d8d3b874576fdd6a2c7a4a4681bef6c98 /models/packages
parentbf77e2163b670797d5bf7199da88789968e47c61 (diff)
downloadgitea-c0ddec8a2a4cd348462257e0ceb253daf5692c32.tar.gz
gitea-c0ddec8a2a4cd348462257e0ceb253daf5692c32.zip
Revert "Add Debian package registry" (#24412)
Reverts go-gitea/gitea#22854
Diffstat (limited to 'models/packages')
-rw-r--r--models/packages/container/search.go11
-rw-r--r--models/packages/debian/search.go131
-rw-r--r--models/packages/descriptor.go26
-rw-r--r--models/packages/package.go19
-rw-r--r--models/packages/package_file.go25
-rw-r--r--models/packages/package_version.go6
6 files changed, 31 insertions, 187 deletions
diff --git a/models/packages/container/search.go b/models/packages/container/search.go
index 0d3664d384..b65c8634d6 100644
--- a/models/packages/container/search.go
+++ b/models/packages/container/search.go
@@ -101,7 +101,16 @@ func getContainerBlobsLimit(ctx context.Context, opts *BlobSearchOptions, limit
return nil, err
}
- return packages.GetPackageFileDescriptors(ctx, pfs)
+ pfds := make([]*packages.PackageFileDescriptor, 0, len(pfs))
+ for _, pf := range pfs {
+ pfd, err := packages.GetPackageFileDescriptor(ctx, pf)
+ if err != nil {
+ return nil, err
+ }
+ pfds = append(pfds, pfd)
+ }
+
+ return pfds, nil
}
// GetManifestVersions gets all package versions representing the matching manifest
diff --git a/models/packages/debian/search.go b/models/packages/debian/search.go
deleted file mode 100644
index 332a4f7040..0000000000
--- a/models/packages/debian/search.go
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright 2023 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package debian
-
-import (
- "context"
- "strconv"
-
- "code.gitea.io/gitea/models/db"
- "code.gitea.io/gitea/models/packages"
- debian_module "code.gitea.io/gitea/modules/packages/debian"
-
- "xorm.io/builder"
-)
-
-type PackageSearchOptions struct {
- OwnerID int64
- Distribution string
- Component string
- Architecture string
-}
-
-// SearchLatestPackages gets the latest packages matching the search options
-func SearchLatestPackages(ctx context.Context, opts *PackageSearchOptions) ([]*packages.PackageFileDescriptor, error) {
- var cond builder.Cond = builder.Eq{
- "package_file.is_lead": true,
- "package.type": packages.TypeDebian,
- "package.owner_id": opts.OwnerID,
- "package.is_internal": false,
- "package_version.is_internal": false,
- }
-
- props := make(map[string]string)
- if opts.Distribution != "" {
- props[debian_module.PropertyDistribution] = opts.Distribution
- }
- if opts.Component != "" {
- props[debian_module.PropertyComponent] = opts.Component
- }
- if opts.Architecture != "" {
- props[debian_module.PropertyArchitecture] = opts.Architecture
- }
-
- if len(props) > 0 {
- var propsCond builder.Cond = builder.Eq{
- "package_property.ref_type": packages.PropertyTypeFile,
- }
- propsCond = propsCond.And(builder.Expr("package_property.ref_id = package_file.id"))
-
- propsCondBlock := builder.NewCond()
- for name, value := range props {
- propsCondBlock = propsCondBlock.Or(builder.Eq{
- "package_property.name": name,
- "package_property.value": value,
- })
- }
- propsCond = propsCond.And(propsCondBlock)
-
- cond = cond.And(builder.Eq{
- strconv.Itoa(len(props)): builder.Select("COUNT(*)").Where(propsCond).From("package_property"),
- })
- }
-
- cond = cond.
- And(builder.Expr("pv2.id IS NULL"))
-
- joinCond := builder.
- Expr("package_version.package_id = pv2.package_id AND (package_version.created_unix < pv2.created_unix OR (package_version.created_unix = pv2.created_unix AND package_version.id < pv2.id))").
- And(builder.Eq{"pv2.is_internal": false})
-
- pfs := make([]*packages.PackageFile, 0, 10)
- err := db.GetEngine(ctx).
- Table("package_file").
- Select("package_file.*").
- Join("INNER", "package_version", "package_version.id = package_file.version_id").
- Join("LEFT", "package_version pv2", joinCond).
- Join("INNER", "package", "package.id = package_version.package_id").
- Where(cond).
- Desc("package_version.created_unix").
- Find(&pfs)
- if err != nil {
- return nil, err
- }
-
- return packages.GetPackageFileDescriptors(ctx, pfs)
-}
-
-// GetDistributions gets all available distributions
-func GetDistributions(ctx context.Context, ownerID int64) ([]string, error) {
- return getDistinctPropertyValues(ctx, ownerID, "", debian_module.PropertyDistribution)
-}
-
-// GetComponents gets all available components for the given distribution
-func GetComponents(ctx context.Context, ownerID int64, distribution string) ([]string, error) {
- return getDistinctPropertyValues(ctx, ownerID, distribution, debian_module.PropertyComponent)
-}
-
-// GetArchitectures gets all available architectures for the given distribution
-func GetArchitectures(ctx context.Context, ownerID int64, distribution string) ([]string, error) {
- return getDistinctPropertyValues(ctx, ownerID, distribution, debian_module.PropertyArchitecture)
-}
-
-func getDistinctPropertyValues(ctx context.Context, ownerID int64, distribution, propName string) ([]string, error) {
- var cond builder.Cond = builder.Eq{
- "package_property.ref_type": packages.PropertyTypeFile,
- "package_property.name": propName,
- "package.type": packages.TypeDebian,
- "package.owner_id": ownerID,
- }
- if distribution != "" {
- innerCond := builder.
- Expr("pp.ref_id = package_property.ref_id").
- And(builder.Eq{
- "pp.ref_type": packages.PropertyTypeFile,
- "pp.name": debian_module.PropertyDistribution,
- "pp.value": distribution,
- })
- cond = cond.And(builder.Exists(builder.Select("pp.ref_id").From("package_property pp").Where(innerCond)))
- }
-
- values := make([]string, 0, 5)
- return values, db.GetEngine(ctx).
- Table("package_property").
- Distinct("package_property.value").
- Join("INNER", "package_file", "package_file.id = package_property.ref_id").
- Join("INNER", "package_version", "package_version.id = package_file.version_id").
- Join("INNER", "package", "package.id = package_version.package_id").
- Where(cond).
- Find(&values)
-}
diff --git a/models/packages/descriptor.go b/models/packages/descriptor.go
index 9256dd5630..974c5b2c36 100644
--- a/models/packages/descriptor.go
+++ b/models/packages/descriptor.go
@@ -18,7 +18,6 @@ import (
"code.gitea.io/gitea/modules/packages/conan"
"code.gitea.io/gitea/modules/packages/conda"
"code.gitea.io/gitea/modules/packages/container"
- "code.gitea.io/gitea/modules/packages/debian"
"code.gitea.io/gitea/modules/packages/helm"
"code.gitea.io/gitea/modules/packages/maven"
"code.gitea.io/gitea/modules/packages/npm"
@@ -128,9 +127,13 @@ func GetPackageDescriptor(ctx context.Context, pv *PackageVersion) (*PackageDesc
return nil, err
}
- pfds, err := GetPackageFileDescriptors(ctx, pfs)
- if err != nil {
- return nil, err
+ pfds := make([]*PackageFileDescriptor, 0, len(pfs))
+ for _, pf := range pfs {
+ pfd, err := GetPackageFileDescriptor(ctx, pf)
+ if err != nil {
+ return nil, err
+ }
+ pfds = append(pfds, pfd)
}
var metadata interface{}
@@ -147,8 +150,6 @@ func GetPackageDescriptor(ctx context.Context, pv *PackageVersion) (*PackageDesc
metadata = &conda.VersionMetadata{}
case TypeContainer:
metadata = &container.Metadata{}
- case TypeDebian:
- metadata = &debian.Metadata{}
case TypeGeneric:
// generic packages have no metadata
case TypeHelm:
@@ -209,19 +210,6 @@ func GetPackageFileDescriptor(ctx context.Context, pf *PackageFile) (*PackageFil
}, nil
}
-// GetPackageFileDescriptors gets the package file descriptors for the package files
-func GetPackageFileDescriptors(ctx context.Context, pfs []*PackageFile) ([]*PackageFileDescriptor, error) {
- pfds := make([]*PackageFileDescriptor, 0, len(pfs))
- for _, pf := range pfs {
- pfd, err := GetPackageFileDescriptor(ctx, pf)
- if err != nil {
- return nil, err
- }
- pfds = append(pfds, pfd)
- }
- return pfds, nil
-}
-
// GetPackageDescriptors gets the package descriptions for the versions
func GetPackageDescriptors(ctx context.Context, pvs []*PackageVersion) ([]*PackageDescriptor, error) {
pds := make([]*PackageDescriptor, 0, len(pvs))
diff --git a/models/packages/package.go b/models/packages/package.go
index 579e9e4d53..ccc9257c31 100644
--- a/models/packages/package.go
+++ b/models/packages/package.go
@@ -36,7 +36,6 @@ const (
TypeConan Type = "conan"
TypeConda Type = "conda"
TypeContainer Type = "container"
- TypeDebian Type = "debian"
TypeGeneric Type = "generic"
TypeHelm Type = "helm"
TypeMaven Type = "maven"
@@ -56,7 +55,6 @@ var TypeList = []Type{
TypeConan,
TypeConda,
TypeContainer,
- TypeDebian,
TypeGeneric,
TypeHelm,
TypeMaven,
@@ -84,8 +82,6 @@ func (pt Type) Name() string {
return "Conda"
case TypeContainer:
return "Container"
- case TypeDebian:
- return "Debian"
case TypeGeneric:
return "Generic"
case TypeHelm:
@@ -125,8 +121,6 @@ func (pt Type) SVGName() string {
return "gitea-conda"
case TypeContainer:
return "octicon-container"
- case TypeDebian:
- return "gitea-debian"
case TypeGeneric:
return "octicon-package"
case TypeHelm:
@@ -160,7 +154,6 @@ type Package struct {
Name string `xorm:"NOT NULL"`
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
SemverCompatible bool `xorm:"NOT NULL DEFAULT false"`
- IsInternal bool `xorm:"INDEX NOT NULL DEFAULT false"`
}
// TryInsertPackage inserts a package. If a package exists already, ErrDuplicatePackage is returned
@@ -221,10 +214,9 @@ func GetPackageByID(ctx context.Context, packageID int64) (*Package, error) {
// GetPackageByName gets a package by name
func GetPackageByName(ctx context.Context, ownerID int64, packageType Type, name string) (*Package, error) {
var cond builder.Cond = builder.Eq{
- "package.owner_id": ownerID,
- "package.type": packageType,
- "package.lower_name": strings.ToLower(name),
- "package.is_internal": false,
+ "package.owner_id": ownerID,
+ "package.type": packageType,
+ "package.lower_name": strings.ToLower(name),
}
p := &Package{}
@@ -244,9 +236,8 @@ func GetPackageByName(ctx context.Context, ownerID int64, packageType Type, name
// GetPackagesByType gets all packages of a specific type
func GetPackagesByType(ctx context.Context, ownerID int64, packageType Type) ([]*Package, error) {
var cond builder.Cond = builder.Eq{
- "package.owner_id": ownerID,
- "package.type": packageType,
- "package.is_internal": false,
+ "package.owner_id": ownerID,
+ "package.type": packageType,
}
ps := make([]*Package, 0, 10)
diff --git a/models/packages/package_file.go b/models/packages/package_file.go
index 337ab1135a..97e7a0d407 100644
--- a/models/packages/package_file.go
+++ b/models/packages/package_file.go
@@ -117,15 +117,13 @@ func DeleteFileByID(ctx context.Context, fileID int64) error {
// PackageFileSearchOptions are options for SearchXXX methods
type PackageFileSearchOptions struct {
- OwnerID int64
- PackageType string
- VersionID int64
- Query string
- CompositeKey string
- Properties map[string]string
- OlderThan time.Duration
- HashAlgorithmn string
- Hash string
+ OwnerID int64
+ PackageType string
+ VersionID int64
+ Query string
+ CompositeKey string
+ Properties map[string]string
+ OlderThan time.Duration
db.Paginator
}
@@ -184,15 +182,6 @@ func (opts *PackageFileSearchOptions) toConds() builder.Cond {
cond = cond.And(builder.Lt{"package_file.created_unix": time.Now().Add(-opts.OlderThan).Unix()})
}
- if opts.Hash != "" && (opts.HashAlgorithmn == "md5" || opts.HashAlgorithmn == "sha1" || opts.HashAlgorithmn == "sha256" || opts.HashAlgorithmn == "sha512") {
- innerCond := builder.
- Expr("package_blob.id = package_file.blob_id").
- And(builder.Eq{
- "package_blob.hash_" + opts.HashAlgorithmn: opts.Hash,
- })
- cond = cond.And(builder.Exists(builder.Select("package_blob.id").From("package_blob").Where(innerCond)))
- }
-
return cond
}
diff --git a/models/packages/package_version.go b/models/packages/package_version.go
index ab1bcddae5..759c20abed 100644
--- a/models/packages/package_version.go
+++ b/models/packages/package_version.go
@@ -173,7 +173,7 @@ const (
)
// PackageSearchOptions are options for SearchXXX methods
-// All fields optional and are not used if they have their default value (nil, "", 0)
+// Besides IsInternal are all fields optional and are not used if they have their default value (nil, "", 0)
type PackageSearchOptions struct {
OwnerID int64
RepoID int64
@@ -192,9 +192,7 @@ type PackageSearchOptions struct {
func (opts *PackageSearchOptions) toConds() builder.Cond {
cond := builder.NewCond()
if !opts.IsInternal.IsNone() {
- cond = builder.Eq{
- "package_version.is_internal": opts.IsInternal.IsTrue(),
- }
+ cond = builder.Eq{"package_version.is_internal": opts.IsInternal.IsTrue()}
}
if opts.OwnerID != 0 {