aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2023-04-08 10:14:34 +0300
committerArthur Zamarin <arthurzam@gentoo.org>2023-04-08 10:17:39 +0300
commit3f491e2eea87dfd70119e6c55b0bfe6d1fe60d70 (patch)
treea9572dd4a0cb9725f3fda3f09c054b72049fe263 /pkg/portage
parentapp/packages/search: redirect to the first result if there is only one (diff)
downloadsoko-3f491e2eea87dfd70119e6c55b0bfe6d1fe60d70.tar.gz
soko-3f491e2eea87dfd70119e6c55b0bfe6d1fe60d70.tar.bz2
soko-3f491e2eea87dfd70119e6c55b0bfe6d1fe60d70.zip
update/repo: add package.deprecated parser & collector
Bug: https://bugs.gentoo.org/903987 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'pkg/portage')
-rw-r--r--pkg/portage/repository/deprecated.go145
-rw-r--r--pkg/portage/update.go4
2 files changed, 148 insertions, 1 deletions
diff --git a/pkg/portage/repository/deprecated.go b/pkg/portage/repository/deprecated.go
new file mode 100644
index 0000000..4c642b7
--- /dev/null
+++ b/pkg/portage/repository/deprecated.go
@@ -0,0 +1,145 @@
+// Contains functions to import package deprecated entries into the database
+//
+// Example
+//
+// ## # Dev E. Loper <developer@gentoo.org> (2019-07-01)
+// ## # Deprecated upstream, see HOMEPAGE
+// ## dev-perl/Mail-Sender
+//
+
+package repository
+
+import (
+ "soko/pkg/config"
+ "soko/pkg/database"
+ "soko/pkg/logger"
+ "soko/pkg/models"
+ "soko/pkg/portage/utils"
+ "strings"
+
+ "github.com/go-pg/pg/v10"
+)
+
+// isPackagesDeprecated checks whether the path
+// points to a package.mask file
+func isPackagesDeprecated(path string) bool {
+ return path == "profiles/package.deprecated"
+}
+
+// UpdatePackagesDeprecated updates all entries in
+// the Deprecated table in the database
+func UpdatePackagesDeprecated(path string) {
+
+ splittedLine := strings.Split(path, "\t")
+
+ var status, changedFile string
+ switch len(splittedLine) {
+ case 2:
+ status = splittedLine[0]
+ changedFile = splittedLine[1]
+ case 1:
+ // This happens in case of a full update
+ status = "A"
+ changedFile = splittedLine[0]
+ default:
+ // should not happen
+ return
+ }
+
+ if status != "D" && isPackagesDeprecated(changedFile) {
+ logger.Info.Println("Updating package.deprecated")
+
+ // delete all existing entries before parsing the file again
+ // in future we might implement a incremental version here
+ database.TruncateTable[models.DeprecatedPackage]("versions")
+
+ for _, entry := range getDeprecatedPackages(changedFile) {
+ parsePackagesDeprecated(entry)
+ }
+ }
+}
+
+// parse the package.mask entries and
+// update the DeprecatedPackage table in the database
+func parsePackagesDeprecated(entry string) {
+ packageLines := strings.Split(entry, "\n")
+ if len(packageLines) >= 3 {
+ packageLine, packageLines := packageLines[0], packageLines[1:]
+ author, authorEmail, date := parseAuthorLine(packageLine)
+
+ var reason string
+ packageLine, packageLines = packageLines[0], packageLines[1:]
+ for strings.HasPrefix(packageLine, "#") {
+ reason = reason + " " + strings.Replace(packageLine, "# ", "", 1)
+ packageLine, packageLines = packageLines[0], packageLines[1:]
+ }
+
+ packageLines = append(packageLines, packageLine)
+
+ for _, version := range packageLines {
+ entry := &models.DeprecatedPackage{
+ Author: author,
+ AuthorEmail: authorEmail,
+ Date: date,
+ Reason: reason,
+ Versions: version,
+ }
+
+ _, err := database.DBCon.Model(entry).OnConflict("(versions) DO UPDATE").Insert()
+ if err != nil {
+ logger.Error.Println("Error while inserting/updating package deprecated entry", err)
+ }
+ }
+ }
+
+}
+
+// get all entries from the package.deprecated file
+func getDeprecatedPackages(path string) []string {
+ var deprecates []string
+ lines, err := utils.ReadLines(config.PortDir() + "/" + path)
+ if err != nil {
+ logger.Error.Println("Could not read package.deprecated file, aborting import, err:", err)
+ return deprecates
+ }
+
+ line, lines := lines[0], lines[1:]
+ for !strings.Contains(line, "#--- END OF EXAMPLES ---") {
+ line, lines = lines[0], lines[1:]
+ }
+ lines = lines[1:]
+
+ return strings.Split(strings.Join(lines, "\n"), "\n\n")
+}
+
+// Calculate all versions that are currently
+// deprecated and update the DeprecatedToVersion Table
+func CalculateDeprecatedToVersion() {
+ database.TruncateTable[models.DeprecatedToVersion]("id")
+
+ var deprecates []*models.DeprecatedPackage
+ err := database.DBCon.Model(&deprecates).Select()
+ if err != nil && err != pg.ErrNoRows {
+ logger.Error.Println("Failed to retrieve package masks. Aborting update", err)
+ return
+ }
+
+ for _, deprecate := range deprecates {
+ versionSpecifier := deprecate.Versions
+ packageAtom := versionSpecifierToPackageAtom(versionSpecifier)
+ versions := utils.CalculateAffectedVersions(versionSpecifier, packageAtom)
+
+ for _, version := range versions {
+ depToVersion := &models.DeprecatedToVersion{
+ Id: versionSpecifier + "-" + version.Id,
+ DeprecatedVersions: versionSpecifier,
+ VersionId: version.Id,
+ }
+
+ _, err := database.DBCon.Model(depToVersion).OnConflict("(id) DO UPDATE").Insert()
+ if err != nil {
+ logger.Error.Println("Error while inserting mask to version entry", err)
+ }
+ }
+ }
+}
diff --git a/pkg/portage/update.go b/pkg/portage/update.go
index 39d8521..a9c5199 100644
--- a/pkg/portage/update.go
+++ b/pkg/portage/update.go
@@ -38,7 +38,7 @@ func Update() {
updateHistory()
repository.CalculateMaskedVersions()
-
+ repository.CalculateDeprecatedToVersion()
}
// updateMetadata updates all USE flags, package masks and arches in the database
@@ -48,6 +48,7 @@ func Update() {
// - profiles/use.local.desc
// - profiles/desc/*
// - profiles/package.mask
+// - profiles/package.deprecated
// - profiles/arch.list
//
// It works incrementally so that files are only parsed and updated whenever the
@@ -66,6 +67,7 @@ func updateMetadata() {
for _, path := range changed {
repository.UpdateUse(path)
repository.UpdateMask(path)
+ repository.UpdatePackagesDeprecated(path)
repository.UpdateArch(path)
}