pull/109/head
Giovanni Harting 8 months ago
parent 47f0fb6c66
commit 2631aada64
  1. 48
      package.go
  2. 3
      pkgbuild.go

@ -15,40 +15,46 @@ import (
type Package string
// Name returns the name from Package
func (path Package) Name() string {
fNameSplit := strings.Split(filepath.Base(string(path)), "-")
// Name returns package's name
func (pkg Package) Name() string {
fNameSplit := strings.Split(filepath.Base(string(pkg)), "-")
return strings.Join(fNameSplit[:len(fNameSplit)-3], "-")
}
func (path Package) MArch() string {
splitPath := strings.Split(string(path), string(filepath.Separator))
// MArch returns package's march
func (pkg Package) MArch() string {
splitPath := strings.Split(string(pkg), string(filepath.Separator))
return strings.Join(strings.Split(splitPath[len(splitPath)-4], "-")[1:], "-")
}
func (path Package) Repo() dbpackage.Repository {
splitPath := strings.Split(string(path), string(filepath.Separator))
// Repo returns package's dbpackage.Repository
func (pkg Package) Repo() dbpackage.Repository {
splitPath := strings.Split(string(pkg), string(filepath.Separator))
return dbpackage.Repository(strings.Split(splitPath[len(splitPath)-4], "-")[0])
}
func (path Package) FullRepo() string {
splitPath := strings.Split(string(path), string(filepath.Separator))
// FullRepo returns package's dbpackage.Repository-march
func (pkg Package) FullRepo() string {
splitPath := strings.Split(string(pkg), string(filepath.Separator))
return splitPath[len(splitPath)-4]
}
func (path Package) Version() string {
fNameSplit := strings.Split(filepath.Base(string(path)), "-")
// Version returns version extracted from package
func (pkg Package) Version() string {
fNameSplit := strings.Split(filepath.Base(string(pkg)), "-")
return strings.Join(fNameSplit[len(fNameSplit)-3:len(fNameSplit)-1], "-")
}
func (path Package) Arch() string {
fNameSplit := strings.Split(filepath.Base(string(path)), "-")
// Arch returns package's Architecture
func (pkg Package) Arch() string {
fNameSplit := strings.Split(filepath.Base(string(pkg)), "-")
fNameSplit = strings.Split(fNameSplit[len(fNameSplit)-1], ".")
return fNameSplit[0]
}
func (path Package) HasValidSignature() (bool, error) {
cmd := exec.Command("gpg", "--verify", string(path)+".sig")
// HasValidSignature returns if package has valid detached signature file
func (pkg Package) HasValidSignature() (bool, error) {
cmd := exec.Command("gpg", "--verify", string(pkg)+".sig")
res, err := cmd.CombinedOutput()
if cmd.ProcessState.ExitCode() == 2 || cmd.ProcessState.ExitCode() == 1 {
return false, nil
@ -61,21 +67,23 @@ func (path Package) HasValidSignature() (bool, error) {
return false, nil
}
func (path *Package) DBPackage(db *ent.Client) (*ent.DbPackage, error) {
return path.DBPackageIsolated(path.MArch(), path.Repo(), db)
// DBPackage returns ent.DBPackage for package
func (pkg *Package) DBPackage(db *ent.Client) (*ent.DbPackage, error) {
return pkg.DBPackageIsolated(pkg.MArch(), pkg.Repo(), db)
}
func (path *Package) DBPackageIsolated(march string, repo dbpackage.Repository, db *ent.Client) (*ent.DbPackage, error) {
// DBPackageIsolated returns ent.DBPackage like DBPackage, but not relying on the path for march and repo
func (pkg *Package) DBPackageIsolated(march string, repo dbpackage.Repository, db *ent.Client) (*ent.DbPackage, error) {
dbPkg, err := db.DbPackage.Query().Where(func(s *sql.Selector) {
s.Where(
sql.And(
sqljson.ValueContains(dbpackage.FieldPackages, path.Name()),
sqljson.ValueContains(dbpackage.FieldPackages, pkg.Name()),
sql.EQ(dbpackage.FieldMarch, march),
sql.EQ(dbpackage.FieldRepository, repo)),
)
}).Only(context.Background())
if ent.IsNotFound(err) {
log.Debugf("Not found in database: %s", path.Name())
log.Debugf("Not found in database: %s", pkg.Name())
return nil, err
} else if err != nil {
return nil, err

@ -7,15 +7,18 @@ import (
type PKGBUILD string
// FullRepo returns full-repo from PKGBUILD'S path
func (p PKGBUILD) FullRepo() string {
sPkgbuild := strings.Split(string(p), string(filepath.Separator))
return sPkgbuild[len(sPkgbuild)-2]
}
// Repo returns repo from PKGBUILD's path
func (p PKGBUILD) Repo() string {
return strings.Split(p.FullRepo(), "-")[0]
}
// PkgBase returns pkgbase from PKGBUILD's path
func (p PKGBUILD) PkgBase() string {
sPkgbuild := strings.Split(string(p), string(filepath.Separator))
return sPkgbuild[len(sPkgbuild)-4]

Loading…
Cancel
Save