mirror update: add -max-versions to keep the N most recent versions

This commit is contained in:
Rascalov authored and André Roth committed 2026-11-05 11:21:36 +01:00
1 parent 296e901cb6
commit 5bc1047ba8
4 files changed
+81 -36

No files matched your search

+19 -2
View File
@@ -520,8 +520,10 @@ type mirrorUpdateParams struct {
ForceUpdate bool ` json:"ForceUpdate"`
// Set "true" to skip downloading already downloaded packages
SkipExistingPackages bool ` json:"SkipExistingPackages"`
// Set "true" to download only the latest version per package/architecture
// Set "true" to download only the latest version per package/architecture (same as `MaxVersions`: 1)
LatestOnly bool ` json:"LatestOnly"`
// Download only the N most recent versions per package/architecture, 0 means all versions
MaxVersions int ` json:"MaxVersions" example:"5"`
}
// @Summary Update Mirror
@@ -573,6 +575,14 @@ func apiMirrorsUpdate(c *gin.Context) {
}
}
if b.MaxVersions < 0 {
AbortWithJSONError(c, 400, fmt.Errorf("MaxVersions should be a positive number"))
return
}
if b.LatestOnly && b.MaxVersions == 0 {
b.MaxVersions = 1
}
verifier, err := getVerifier(b.Keyrings)
if err != nil {
AbortWithJSONError(c, 400, fmt.Errorf("unable to initialize GPG verifier: %s", err))
@@ -640,8 +650,15 @@ func apiMirrorsUpdate(c *gin.Context) {
}
}
if b.MaxVersions > 0 {
_, _, err := remote.FilterLatest(b.MaxVersions)
if err != nil {
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
}
}
queue, downloadSize, err := remote.BuildDownloadQueue(context.PackagePool(), taskCollectionFactory.PackageCollection(),
taskCollectionFactory.ChecksumCollection(nil), b.SkipExistingPackages, b.LatestOnly)
taskCollectionFactory.ChecksumCollection(nil), b.SkipExistingPackages)
if err != nil {
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
}