100 lines
2.3 KiB
Go
100 lines
2.3 KiB
Go
|
package packages
|
||
|
|
||
|
import (
|
||
|
"brunel/deb"
|
||
|
"compress/bzip2"
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
const nest64Url = "https://ppa.pika-os.com/dists/pika/nest/binary-amd64/Packages.bz2"
|
||
|
const canary64Url = "https://ppa.pika-os.com/dists/pika/canary/binary-amd64/Packages.bz2"
|
||
|
const nest32Url = "https://ppa.pika-os.com/dists/pika/nest/binary-i386/Packages.bz2"
|
||
|
const canary32Url = "https://ppa.pika-os.com/dists/pika/canary/binary-i386/Packages.bz2"
|
||
|
|
||
|
type freezeItem struct {
|
||
|
Name string
|
||
|
Ver string
|
||
|
}
|
||
|
|
||
|
func GetFreezeItems() ([]freezeItem, []freezeItem, error) {
|
||
|
freeze64, err := compareRepositories(nest64Url, canary64Url)
|
||
|
if err != nil {
|
||
|
return nil, nil, fmt.Errorf("error comparing 64-bit repositories: %w", err)
|
||
|
}
|
||
|
|
||
|
freeze32, err := compareRepositories(nest32Url, canary32Url)
|
||
|
if err != nil {
|
||
|
return nil, nil, fmt.Errorf("error comparing 32-bit repositories: %w", err)
|
||
|
}
|
||
|
|
||
|
return freeze64, freeze32, nil
|
||
|
}
|
||
|
|
||
|
func compareRepositories(nestUrl, canaryUrl string) ([]freezeItem, error) {
|
||
|
nestPackages, err := getPackages(nestUrl)
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("error getting nest packages: %w", err)
|
||
|
}
|
||
|
|
||
|
canaryPackages, err := getPackages(canaryUrl)
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("error getting canary packages: %w", err)
|
||
|
}
|
||
|
|
||
|
nestSet := make(map[string]bool)
|
||
|
for _, pkg := range nestPackages {
|
||
|
nestSet[pkg] = true
|
||
|
}
|
||
|
|
||
|
var freezeItems []freezeItem
|
||
|
for _, pkg := range canaryPackages {
|
||
|
if !nestSet[pkg] {
|
||
|
parts := strings.SplitN(pkg, ":", 2)
|
||
|
if len(parts) == 2 {
|
||
|
freezeItems = append(freezeItems, freezeItem{Name: parts[0], Ver: parts[1]})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return freezeItems, nil
|
||
|
}
|
||
|
|
||
|
func getPackages(url string) ([]string, error) {
|
||
|
resp, err := http.Get(url + "?nocache=" + strconv.Itoa(int(time.Now().Unix())))
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("fetching package file: %w", err)
|
||
|
}
|
||
|
defer resp.Body.Close()
|
||
|
|
||
|
rdr := bzip2.NewReader(resp.Body)
|
||
|
sreader := deb.NewControlFileReader(rdr, false, false)
|
||
|
|
||
|
var packages []string
|
||
|
|
||
|
for {
|
||
|
stanza, err := sreader.ReadStanza()
|
||
|
if err != nil || stanza == nil {
|
||
|
break
|
||
|
}
|
||
|
|
||
|
name := stanza["Package"]
|
||
|
versionStr := stanza["Version"]
|
||
|
|
||
|
if name == "" || versionStr == "" {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
if strings.Contains(name, "-dbgsym") {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
packages = append(packages, name+":"+versionStr)
|
||
|
}
|
||
|
|
||
|
return packages, nil
|
||
|
}
|