Skip to content

Commit

Permalink
add index format version and make pkgpath disambiguation code match t…
Browse files Browse the repository at this point in the history
…he canonical format
  • Loading branch information
neutralinsomniac committed Jan 11, 2021
1 parent 617bb8a commit c1a5e36
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
7 changes: 7 additions & 0 deletions cmd/genpkgup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ var arch string
var version string
var showProgress bool

var indexFormatVersion = 1

var pkgpathRe = regexp.MustCompilePOSIX(`^@comment pkgpath=([^ ]+).*$`)

func main() {
Expand Down Expand Up @@ -108,6 +110,11 @@ func main() {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}

// write index format version
fmt.Println(indexFormatVersion)

// write quirks date
fmt.Println(quirksDate)

lines := strings.Split(indexString, "\n")
Expand Down
55 changes: 42 additions & 13 deletions cmd/obsdpkgup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import (
"compress/gzip"
"flag"
"fmt"
"github.com/neutralinsomniac/obsdpkgup/openbsd"
version2 "github.com/neutralinsomniac/obsdpkgup/openbsd/version"
"io/ioutil"
"net/http"
os "os"
"os"
"os/exec"
"regexp"
"sort"
"strconv"
"strings"
"time"

"github.com/neutralinsomniac/obsdpkgup/openbsd"
version2 "github.com/neutralinsomniac/obsdpkgup/openbsd/version"

"suah.dev/protect"
)

Expand Down Expand Up @@ -85,7 +87,7 @@ func parseLocalPkgInfoToPkgList() PkgList {
files, err := ioutil.ReadDir(pkgDbPath)
checkAndExit(err)

pkgpathRe := regexp.MustCompilePOSIX(`^@comment pkgpath=([^ ,]+).*$`)
pkgpathRe := regexp.MustCompilePOSIX(`^@comment pkgpath=([^ ]+).*$`)
isBranchRe := regexp.MustCompilePOSIX(`^@option is-branch$`)

for _, file := range files {
Expand Down Expand Up @@ -215,11 +217,15 @@ func getMirror() string {
}
}

var pkgpathVersionRE = regexp.MustCompile(`^.*/.*/([^ ,]+).*$`)

var cronMode bool
var forceSnapshot bool
var verbose bool
var debug bool

var currentIndexFormatVersion = 1

func main() {
start := time.Now()
_ = protect.Pledge("stdio unveil rpath wpath cpath flock dns inet tty proc exec")
Expand Down Expand Up @@ -263,20 +269,15 @@ func main() {
resp, err = http.Get(pkgUpIndexUrl)
checkAndExit(err)

var pkgUpBytes []byte
switch resp.StatusCode {
case 200:
// grab body
r, err := gzip.NewReader(resp.Body)
checkAndExit(err)
bodyBytes, err := ioutil.ReadAll(r)
pkgUpBytes, err = ioutil.ReadAll(r)
checkAndExit(err)
resp.Body.Close()

// get quirks timestamp from pkgUp
quirksEndIndex := bytes.IndexByte(bodyBytes, '\n')
pkgUpQuirksDateString = string(bodyBytes[:quirksEndIndex])
// now parse the actual package list
allPkgs = parseObsdPkgUpList(string(bodyBytes[quirksEndIndex:]))
case 404:
fmt.Fprintf(os.Stderr, "unable to locate pkgup index at '%s'.\n", pkgUpIndexUrl)
os.Exit(1)
Expand All @@ -285,6 +286,35 @@ func main() {
os.Exit(1)
}

// get + check version
indexFormatVersionEndIndex := bytes.IndexByte(pkgUpBytes, '\n')
indexFormatVersionStr := string(pkgUpBytes[:indexFormatVersionEndIndex])
pkgUpBytes = pkgUpBytes[indexFormatVersionEndIndex+1:]
indexFormatVersion, err := strconv.Atoi(indexFormatVersionStr)
if err != nil {
fmt.Fprintf(os.Stderr, "expected index version %d, got: %s\n", currentIndexFormatVersion, indexFormatVersionStr)
os.Exit(1)
}

if indexFormatVersion != currentIndexFormatVersion {
fmt.Fprintf(os.Stderr, "expected index version %d, got: %d\n", currentIndexFormatVersion, indexFormatVersion)
if currentIndexFormatVersion < indexFormatVersion {
fmt.Fprintf(os.Stderr, "please update obsdpkgup and try again\n", currentIndexFormatVersion, indexFormatVersion)
} else {
fmt.Fprintf(os.Stderr, "wait for remote mirror to update to the current pkgup index format and try again later\n", currentIndexFormatVersion, indexFormatVersion)
}

os.Exit(1)
}

// get quirks timestamp from pkgUp
quirksEndIndex := bytes.IndexByte(pkgUpBytes, '\n')
pkgUpQuirksDateString = string(pkgUpBytes[:quirksEndIndex])
pkgUpBytes = pkgUpBytes[quirksEndIndex+1:]

// now parse the actual package list
allPkgs = parseObsdPkgUpList(string(pkgUpBytes))

// grab mirror quirks
indexString, err := openbsd.GetIndexTxt(mirror)
if err != nil {
Expand Down Expand Up @@ -343,7 +373,6 @@ func main() {

// check all versions to find upgrades
for _, installedVersion := range installedVersions {
versionComparisonResult := 0
bestVersionMatch := installedVersion
NEXTVERSION:
for _, remoteVersion := range allPkgs[name] {
Expand All @@ -353,7 +382,7 @@ func main() {
}

// check for version bump
versionComparisonResult = bestVersionMatch.version.Compare(remoteVersion.version)
var versionComparisonResult = bestVersionMatch.version.Compare(remoteVersion.version)
if versionComparisonResult == -1 {
bestVersionMatch = remoteVersion
} else if versionComparisonResult == 0 && installedVersion.signature != remoteVersion.signature {
Expand Down

0 comments on commit c1a5e36

Please sign in to comment.