From 2f975c71573d99b5425fdab2f63b44a5398653a5 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Thu, 26 Jul 2018 13:58:51 +0100 Subject: [PATCH 1/6] Update vendored dependencies --- Gopkg.lock | 4 +- vendor/github.com/jguer/go-alpm/callbacks.c | 2 +- vendor/github.com/jguer/go-alpm/callbacks.go | 10 ++-- vendor/github.com/jguer/go-alpm/conf.go | 27 ++++++++++ vendor/github.com/jguer/go-alpm/db.go | 25 +++++++++ vendor/github.com/jguer/go-alpm/enums.go | 39 +++++++++++++- vendor/github.com/jguer/go-alpm/sync.go | 27 ++++++++++ vendor/github.com/jguer/go-alpm/trans.go | 54 ++++++++++++++++++++ vendor/github.com/jguer/go-alpm/types.go | 8 +++ vendor/github.com/mikkeloscar/aur/aur.go | 4 +- 10 files changed, 189 insertions(+), 11 deletions(-) create mode 100644 vendor/github.com/jguer/go-alpm/sync.go create mode 100644 vendor/github.com/jguer/go-alpm/trans.go diff --git a/Gopkg.lock b/Gopkg.lock index c3f4ee22..ba84f576 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -11,13 +11,13 @@ branch = "master" name = "github.com/jguer/go-alpm" packages = ["."] - revision = "1114f773cdfb05f577438f7a0538eccabc9cf012" + revision = "c3ee958efac942186012cc67de8fe5e7a5b3685d" [[projects]] branch = "master" name = "github.com/mikkeloscar/aur" packages = ["."] - revision = "2980c04ca5c926b2cb7c4ac3ac8dc0b7f70d29ba" + revision = "f998dbf94dc47ef839c76740efeb673d3459be1f" [solve-meta] analyzer-name = "dep" diff --git a/vendor/github.com/jguer/go-alpm/callbacks.c b/vendor/github.com/jguer/go-alpm/callbacks.c index e36a4295..857506dc 100644 --- a/vendor/github.com/jguer/go-alpm/callbacks.c +++ b/vendor/github.com/jguer/go-alpm/callbacks.c @@ -9,7 +9,7 @@ #include #include -void logCallback(uint16_t level, char *cstring); +void logCallback(alpm_loglevel_t level, char *cstring); void questionCallback(alpm_question_t *question); void go_alpm_log_cb(alpm_loglevel_t level, const char *fmt, va_list arg) { diff --git a/vendor/github.com/jguer/go-alpm/callbacks.go b/vendor/github.com/jguer/go-alpm/callbacks.go index 0078e58a..66467930 100644 --- a/vendor/github.com/jguer/go-alpm/callbacks.go +++ b/vendor/github.com/jguer/go-alpm/callbacks.go @@ -9,7 +9,7 @@ package alpm /* #include #include -void logCallback(uint16_t level, char *cstring); +void logCallback(alpm_loglevel_t level, char *cstring); void go_alpm_log_cb(alpm_loglevel_t level, const char *fmt, va_list arg); void go_alpm_set_logging(alpm_handle_t *handle); void go_alpm_set_question(alpm_handle_t *handle); @@ -20,12 +20,12 @@ import ( "unsafe" ) -type logCallbackSig func(uint16, string) +type logCallbackSig func(LogLevel, string) type questionCallbackSig func(QuestionAny) var DefaultLogLevel = LogWarning -func DefaultLogCallback(lvl uint16, s string) { +func DefaultLogCallback(lvl LogLevel, s string) { if lvl <= DefaultLogLevel { print("go-alpm: ", s) } @@ -35,8 +35,8 @@ var log_callback logCallbackSig var question_callback questionCallbackSig //export logCallback -func logCallback(level uint16, cstring *C.char) { - log_callback(level, C.GoString(cstring)) +func logCallback(level C.alpm_loglevel_t, cstring *C.char) { + log_callback(LogLevel(level), C.GoString(cstring)) } //export questionCallback diff --git a/vendor/github.com/jguer/go-alpm/conf.go b/vendor/github.com/jguer/go-alpm/conf.go index 18033239..62284726 100644 --- a/vendor/github.com/jguer/go-alpm/conf.go +++ b/vendor/github.com/jguer/go-alpm/conf.go @@ -69,6 +69,7 @@ type PacmanConfig struct { type RepoConfig struct { Name string SigLevel SigLevel + Usage Usage Servers []string } @@ -197,6 +198,24 @@ lineloop: case "SigLevel": // TODO: implement SigLevel parsing. continue lineloop + case "Usage": + for _, usage := range line.Values { + switch usage { + case "Sync": + curRepo.Usage |= UsageSync + case "Search": + curRepo.Usage |= UsageSearch + case "Install": + curRepo.Usage |= UsageInstall + case "Upgrade": + curRepo.Usage |= UsageUpgrade + case "All": + curRepo.Usage |= UsageAll + default: + err = fmt.Errorf("unknown option at line %d: %s", rdr.Lineno, line.Name) + break lineloop + } + } case "Server": curRepo.Servers = append(curRepo.Servers, line.Values...) continue lineloop @@ -261,6 +280,13 @@ lineloop: conf.CacheDir = []string{"/var/cache/pacman/pkg/"} //should only be set if the config does not specify this } + for n, _ := range conf.Repos { + repo := &conf.Repos[n] + if repo.Usage == 0 { + repo.Usage = UsageAll + } + } + return conf, err } @@ -316,6 +342,7 @@ func (conf *PacmanConfig) CreateHandle() (*Handle, error) { repoconf.Servers[i] = addr } db.SetServers(repoconf.Servers) + db.SetUsage(repoconf.Usage) } } diff --git a/vendor/github.com/jguer/go-alpm/db.go b/vendor/github.com/jguer/go-alpm/db.go index 214984de..1295e26a 100644 --- a/vendor/github.com/jguer/go-alpm/db.go +++ b/vendor/github.com/jguer/go-alpm/db.go @@ -117,6 +117,11 @@ func (db Db) SetServers(servers []string) { } } +// SetUsage sets the Usage of the database +func (db Db) SetUsage(usage Usage) { + C.alpm_db_set_usage(db.ptr, C.int(usage)) +} + // PkgByName searches a package in db. func (db Db) PkgByName(name string) (*Package, error) { cName := C.CString(name) @@ -151,3 +156,23 @@ func (db Db) PkgCache() PackageList { pkgcache := (*list)(unsafe.Pointer(C.alpm_db_get_pkgcache(db.ptr))) return PackageList{pkgcache, db.handle} } + +func (db Db) Search(targets []string) PackageList { + needles := &C.alpm_list_t{} + head := needles + needles.data = unsafe.Pointer(C.CString(targets[0])) + + for _, str := range targets[1:] { + needles.next = &C.alpm_list_t{} + needles = needles.next + needles.data = unsafe.Pointer(C.CString(str)) + } + + pkglist := (*list)(unsafe.Pointer(C.alpm_db_search(db.ptr, needles))) + + for needles = head; needles != nil; needles = needles.next { + C.free(needles.data) + } + + return PackageList{pkglist, db.handle} +} diff --git a/vendor/github.com/jguer/go-alpm/enums.go b/vendor/github.com/jguer/go-alpm/enums.go index 3c692bc1..cb32b500 100644 --- a/vendor/github.com/jguer/go-alpm/enums.go +++ b/vendor/github.com/jguer/go-alpm/enums.go @@ -89,9 +89,11 @@ const ( SigStatusKeyDisabled ) +type LogLevel uint16 + // Logging levels. const ( - LogError uint16 = 1 << iota + LogError LogLevel = 1 << iota LogWarning LogDebug LogFunction @@ -118,3 +120,38 @@ const ( ValidationSignature ValidationUnkown Validation = 0 ) + +type Usage int + +const ( + UsageSync Usage = 1 << iota + UsageSearch + UsageInstall + UsageUpgrade + UsageAll = (1 << 4) - 1 +) + +type TransFlag int + +const ( + TransFlagNoDeps TransFlag = 1 << iota + TransFlagForce + TransFlagNoSave + TransFlagNoDepVersion + TransFlagCascade + TransFlagRecurse + // 7 is missing + _ + TransFlagDbOnly + TransFlagAllDeps + TransFlagDownloadOnly + TransFlagNoScriptlets + // 12 is missing + _ + TransFlagNoConflicts + TransFlagNeeded + TransFlagAllExplicit + TransFlagUnneeded + TransFlagRecurseAll + TransFlagNoLock +) diff --git a/vendor/github.com/jguer/go-alpm/sync.go b/vendor/github.com/jguer/go-alpm/sync.go new file mode 100644 index 00000000..d5e4ebab --- /dev/null +++ b/vendor/github.com/jguer/go-alpm/sync.go @@ -0,0 +1,27 @@ +// db.go - Functions for database handling. +// +// Copyright (c) 2013 The go-alpm Authors +// +// MIT Licensed. See LICENSE for details. + +package alpm + +/* +#include +*/ +import "C" + +func (h *Handle) SyncSysupgrade(enableDowngrade bool) error { + intEnableDowngrade := C.int(0) + + if enableDowngrade { + intEnableDowngrade = C.int(1) + } + + ret := C.alpm_sync_sysupgrade(h.ptr, intEnableDowngrade) + if ret != 0 { + return h.LastError() + } + + return nil +} diff --git a/vendor/github.com/jguer/go-alpm/trans.go b/vendor/github.com/jguer/go-alpm/trans.go new file mode 100644 index 00000000..92d5a740 --- /dev/null +++ b/vendor/github.com/jguer/go-alpm/trans.go @@ -0,0 +1,54 @@ +// db.go - Functions for database handling. +// +// Copyright (c) 2013 The go-alpm Authors +// +// MIT Licensed. See LICENSE for details. + +package alpm + +/* +#include +*/ +import "C" + +import ( + "unsafe" +) + +func (h *Handle) TransInit(flags TransFlag) error { + ret := C.alpm_trans_init(h.ptr, C.int(flags)) + if ret != 0 { + return h.LastError() + } + + return nil +} + +func (h *Handle) TransRelease() error { + ret := C.alpm_trans_release(h.ptr) + if ret != 0 { + return h.LastError() + } + + return nil +} + +func (h *Handle) TransGetAdd() PackageList { + pkgs := C.alpm_trans_get_add(h.ptr) + return PackageList{(*list)(unsafe.Pointer(pkgs)), *h} +} + +func (h *Handle) TransGetRemove() PackageList { + pkgs := C.alpm_trans_get_remove(h.ptr) + return PackageList{(*list)(unsafe.Pointer(pkgs)), *h} +} + +func (h *Handle) TransGetFalgs() (TransFlag, error) { + flags := C.alpm_trans_get_flags(h.ptr) + + if flags == -1 { + return -1, h.LastError() + } + + return TransFlag(flags), nil +} diff --git a/vendor/github.com/jguer/go-alpm/types.go b/vendor/github.com/jguer/go-alpm/types.go index 91390550..351a21ee 100644 --- a/vendor/github.com/jguer/go-alpm/types.go +++ b/vendor/github.com/jguer/go-alpm/types.go @@ -192,6 +192,14 @@ func (question QuestionAny) QuestionSelectProvider() (QuestionSelectProvider, er return QuestionSelectProvider{}, fmt.Errorf("Can not convert to QuestionInstallIgnorepkg") } +func (question QuestionAny) QuestionReplace() (QuestionReplace, error) { + if question.Type() == QuestionTypeReplacePkg { + return *(*QuestionReplace)(unsafe.Pointer(&question)), nil + } + + return QuestionReplace{}, fmt.Errorf("Can not convert to QuestionReplace") +} + func (question QuestionInstallIgnorepkg) SetInstall(install bool) { if install { question.ptr.install = 1 diff --git a/vendor/github.com/mikkeloscar/aur/aur.go b/vendor/github.com/mikkeloscar/aur/aur.go index 778ea1e1..46db9391 100644 --- a/vendor/github.com/mikkeloscar/aur/aur.go +++ b/vendor/github.com/mikkeloscar/aur/aur.go @@ -2,7 +2,7 @@ package aur import ( "encoding/json" - "fmt" + "errors" "net/http" "net/url" ) @@ -62,7 +62,7 @@ func get(values url.Values) ([]Pkg, error) { } if len(result.Error) > 0 { - return nil, fmt.Errorf(result.Error) + return nil, errors.New(result.Error) } return result.Results, nil From 3180c66f394e3e025fb49e9004a0eec388cd8204 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Tue, 24 Jul 2018 22:00:33 +0100 Subject: [PATCH 2/6] Use alpm's built in searching for -Ss This allows us to support the usage option in pacman.conf This also speeds up the searching --- query.go | 49 +++++++++++++------------------------------------ 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/query.go b/query.go index 7c57d103..6abdd3a4 100644 --- a/query.go +++ b/query.go @@ -260,46 +260,23 @@ func queryRepo(pkgInputN []string) (s repoQuery, n int, err error) { return } - // BottomUp functions - initL := func(len int) int { - if config.SortMode == TopDown { - return 0 + dbList.ForEach(func(db alpm.Db) error { + if len(pkgInputN) == 0 { + pkgs := db.PkgCache() + s = append(s, pkgs.Slice()...) + } else { + pkgs := db.Search(pkgInputN) + s = append(s, pkgs.Slice()...) } - return len - 1 - } - compL := func(len int, i int) bool { - if config.SortMode == TopDown { - return i < len + return nil + }) + + if config.SortMode == BottomUp { + for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { + s[i], s[j] = s[j], s[i] } - return i > -1 - } - finalL := func(i int) int { - if config.SortMode == TopDown { - return i + 1 - } - return i - 1 } - dbS := dbList.Slice() - lenDbs := len(dbS) - for f := initL(lenDbs); compL(lenDbs, f); f = finalL(f) { - pkgS := dbS[f].PkgCache().Slice() - lenPkgs := len(pkgS) - for i := initL(lenPkgs); compL(lenPkgs, i); i = finalL(i) { - match := true - for _, pkgN := range pkgInputN { - if !(strings.Contains(pkgS[i].Name(), pkgN) || strings.Contains(strings.ToLower(pkgS[i].Description()), pkgN)) { - match = false - break - } - } - - if match { - n++ - s = append(s, pkgS[i]) - } - } - } return } From f4aa7f79337fe777b9be04d44b35d4308da59a95 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Wed, 25 Jul 2018 02:04:17 +0100 Subject: [PATCH 3/6] Use alpm_sync_sysupgrade for uprepo This allows us to support the Upgrade Usage option as well as relying on alpm's logic instead of coming up with out own. It is possible that this could lead to showing replaces in the upgrade menu. --- upgrade.go | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/upgrade.go b/upgrade.go index 71fa8df5..5e81ccaf 100644 --- a/upgrade.go +++ b/upgrade.go @@ -297,23 +297,38 @@ func printLocalNewerThanAUR( // upRepo gathers local packages and checks if they have new versions. // Output: Upgrade type package list. func upRepo(local []alpm.Package) (upSlice, error) { - dbList, err := alpmHandle.SyncDbs() - if err != nil { - return nil, err - } - slice := upSlice{} - for _, pkg := range local { - newPkg := pkg.NewVersion(dbList) - if newPkg != nil { - if pkg.ShouldIgnore() { - printIgnoringPackage(pkg, newPkg.Version()) - } else { - slice = append(slice, upgrade{pkg.Name(), newPkg.DB().Name(), pkg.Version(), newPkg.Version()}) - } - } + localDB, err := alpmHandle.LocalDb() + if err != nil { + return slice, err } + + err = alpmHandle.TransInit(alpm.TransFlagNoLock) + if err != nil { + return slice, err + } + + defer alpmHandle.TransRelease() + + alpmHandle.SyncSysupgrade(cmdArgs.existsDouble("u", "sysupgrade")) + alpmHandle.TransGetAdd().ForEach(func(pkg alpm.Package) error { + localPkg, err := localDB.PkgByName(pkg.Name()) + localVer := "-" + + if err == nil { + localVer = localPkg.Version() + } + + slice = append(slice, upgrade{ + pkg.Name(), + pkg.DB().Name(), + localVer, + pkg.Version(), + }) + return nil + }) + return slice, nil } From 42a74c41c53181d632424b58e36772074cf2d106 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Thu, 26 Jul 2018 13:35:19 +0100 Subject: [PATCH 4/6] Show alpm warnings --- callbacks.go | 9 +++++++++ main.go | 1 + 2 files changed, 10 insertions(+) diff --git a/callbacks.go b/callbacks.go index 1b55a0f6..5d0bd22d 100644 --- a/callbacks.go +++ b/callbacks.go @@ -85,3 +85,12 @@ func questionCallback(question alpm.QuestionAny) { } } } + +func logCallback(level alpm.LogLevel, str string) { + switch level { + case alpm.LogWarning: + fmt.Print(bold(yellow(smallArrow)), " ", str) + case alpm.LogError: + fmt.Print(bold(red(smallArrow)), " ", str) + } +} diff --git a/main.go b/main.go index 3966d38e..1c1ec4b7 100644 --- a/main.go +++ b/main.go @@ -191,6 +191,7 @@ func initAlpmHandle() (err error) { } alpmHandle.SetQuestionCallback(questionCallback) + alpmHandle.SetLogCallback(logCallback) return } From dfe7738d6e873a84b82472dbbea526abc641445f Mon Sep 17 00:00:00 2001 From: morganamilo Date: Tue, 31 Jul 2018 00:19:21 +0100 Subject: [PATCH 5/6] Use pacman like text for ignorepkg and newerpkg Now that we are using alpm to fetch packages it generates these mesages and we can not control the format. So change out format to match. --- upgrade.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/upgrade.go b/upgrade.go index 5e81ccaf..39d1e448 100644 --- a/upgrade.go +++ b/upgrade.go @@ -268,10 +268,11 @@ func upAUR( func printIgnoringPackage(pkg alpm.Package, newPkgVersion string) { left, right := getVersionDiff(pkg.Version(), newPkgVersion) - fmt.Println( - yellow(bold(smallArrow)) + fmt.Sprintf( - " Ignoring package upgrade: %s (%s -> %s)", - cyan(pkg.Name()), left, right)) + fmt.Printf("%s %s: ignoring package upgrade (%s => %s)\n", + yellow(bold(smallArrow)), + cyan(pkg.Name()), + left, right, + ) } func printLocalNewerThanAUR( @@ -284,12 +285,12 @@ func printLocalNewerThanAUR( left, right := getVersionDiff(pkg.Version(), aurPkg.Version) - if !isDevelName(pkg.Name()) && - alpm.VerCmp(pkg.Version(), aurPkg.Version) > 0 { - fmt.Println( - yellow(bold(smallArrow)) + fmt.Sprintf( - " Local package is newer than AUR: %s (%s -> %s)", - cyan(pkg.Name()), left, right)) + if !isDevelName(pkg.Name()) && alpm.VerCmp(pkg.Version(), aurPkg.Version) > 0 { + fmt.Printf("%s %s: local (%s) is newer than AUR (%s)\n", + yellow(bold(smallArrow)), + cyan(pkg.Name()), + left, right, + ) } } } From 06a45bad59d4d2c698312865c570292c7542a2e8 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Tue, 31 Jul 2018 01:56:41 +0100 Subject: [PATCH 6/6] Don't return length with queryRepo --- cmd.go | 3 ++- query.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd.go b/cmd.go index b95e3faa..7be8e6ee 100644 --- a/cmd.go +++ b/cmd.go @@ -461,7 +461,8 @@ func numberMenu(pkgS []string, flags []string) (err error) { lenaq = len(aq) } if mode == ModeRepo || mode == ModeAny { - pq, lenpq, repoErr = queryRepo(pkgS) + pq, repoErr = queryRepo(pkgS) + lenpq = len(pq) if repoErr != nil { return err } diff --git a/query.go b/query.go index 6abdd3a4..bcf0d455 100644 --- a/query.go +++ b/query.go @@ -169,7 +169,7 @@ func syncSearch(pkgS []string) (err error) { aq, aurErr = narrowSearch(pkgS, true) } if mode == ModeRepo || mode == ModeAny { - pq, _, repoErr = queryRepo(pkgS) + pq, repoErr = queryRepo(pkgS) if repoErr != nil { return err } @@ -254,7 +254,7 @@ func syncInfo(pkgS []string) (err error) { } // Search handles repo searches. Creates a RepoSearch struct. -func queryRepo(pkgInputN []string) (s repoQuery, n int, err error) { +func queryRepo(pkgInputN []string) (s repoQuery, err error) { dbList, err := alpmHandle.SyncDbs() if err != nil { return