Add support for deleting builds from yumrepofs

This commit is contained in:
Mustafa Gezen 2022-11-21 00:58:14 +01:00
parent be2b871fff
commit c6bec99698
Signed by untrusted user who does not match committer: mustafa
GPG Key ID: DCDF010D946438C1

View File

@ -79,7 +79,6 @@ type UpdateRepoRequest struct {
BuildIDs []string `json:"buildId"` BuildIDs []string `json:"buildId"`
TaskID *string `json:"taskId"` TaskID *string `json:"taskId"`
ForceRepoId string `json:"forceRepoId"` ForceRepoId string `json:"forceRepoId"`
// todo(mustafa): Add support for deleting packages
Delete bool `json:"delete"` Delete bool `json:"delete"`
ForceNonModular bool `json:"forceNonModular"` ForceNonModular bool `json:"forceNonModular"`
DisableSigning bool `json:"disableSigning"` DisableSigning bool `json:"disableSigning"`
@ -1012,9 +1011,11 @@ func (c *Controller) makeRepoChanges(tx peridotdb.Access, req *UpdateRepoRequest
} }
// Get artifacts to skip deletion // Get artifacts to skip deletion
if !req.Delete {
for _, artifact := range artifacts { for _, artifact := range artifacts {
skipDeleteArtifacts = append(skipDeleteArtifacts, strings.TrimSuffix(filepath.Base(artifact.Name), ".rpm")) skipDeleteArtifacts = append(skipDeleteArtifacts, strings.TrimSuffix(filepath.Base(artifact.Name), ".rpm"))
} }
}
var repos models.Repositories var repos models.Repositories
@ -1308,8 +1309,8 @@ func (c *Controller) makeRepoChanges(tx peridotdb.Access, req *UpdateRepoRequest
archName = fmt.Sprintf("%s.%s", noDebugInfoName, artifact.Arch) archName = fmt.Sprintf("%s.%s", noDebugInfoName, artifact.Arch)
} }
shouldAdd := true shouldAdd := !req.Delete
if arch != "src" && moduleStream == nil { if arch != "src" && moduleStream == nil && !req.Delete {
// If repo has a list for inclusion, then the artifact has to pass that first // If repo has a list for inclusion, then the artifact has to pass that first
if len(repo.IncludeFilter) > 0 { if len(repo.IncludeFilter) > 0 {
// If the artifact isn't forced, it should be in the include list or additional multilib list // If the artifact isn't forced, it should be in the include list or additional multilib list
@ -1491,15 +1492,17 @@ func (c *Controller) makeRepoChanges(tx peridotdb.Access, req *UpdateRepoRequest
var nFilelists []*yummeta.FilelistsPackage var nFilelists []*yummeta.FilelistsPackage
var nOther []*yummeta.OtherPackage var nOther []*yummeta.OtherPackage
var deleteIds []string var deleteIds []string
if !req.NoDeletePrevious || moduleStream != nil { if (!req.NoDeletePrevious || moduleStream != nil) || req.Delete {
for _, pkg := range primaryRoot.Packages { for _, pkg := range primaryRoot.Packages {
shouldAdd := true shouldAdd := !req.Delete
if !req.Delete {
for _, artifact := range currentActiveArtifacts { for _, artifact := range currentActiveArtifacts {
noRpmName := strings.TrimSuffix(filepath.Base(artifact.Name), ".rpm") noRpmName := strings.TrimSuffix(filepath.Base(artifact.Name), ".rpm")
if filepath.Base(artifact.Name) == filepath.Base(pkg.Location.Href) && !utils.StrContains(noRpmName, changes.ModifiedPackages) && !utils.StrContains(noRpmName, changes.AddedPackages) && !utils.StrContains(noRpmName, skipDeleteArtifacts) { if filepath.Base(artifact.Name) == filepath.Base(pkg.Location.Href) && !utils.StrContains(noRpmName, changes.ModifiedPackages) && !utils.StrContains(noRpmName, changes.AddedPackages) && !utils.StrContains(noRpmName, skipDeleteArtifacts) {
shouldAdd = false shouldAdd = false
} }
} }
}
if !shouldAdd { if !shouldAdd {
c.log.Infof("deleting %s", pkg.Location.Href) c.log.Infof("deleting %s", pkg.Location.Href)
deleteIds = append(deleteIds, pkg.Checksum.Value) deleteIds = append(deleteIds, pkg.Checksum.Value)