From 3905dd86a4a98d672450c570246212dfedca8e8f Mon Sep 17 00:00:00 2001 From: Jguer Date: Thu, 25 May 2017 00:28:35 +0100 Subject: [PATCH] By default yay uses Package Version for updates. Use --timeupdates to set updates based on modification time. Closes #9 --- aur/aur.go | 15 +++++++++++++-- config/config.go | 2 ++ yay.go | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/aur/aur.go b/aur/aur.go index 55a954ca..fbeabec8 100644 --- a/aur/aur.go +++ b/aur/aur.go @@ -167,7 +167,8 @@ func Upgrade(flags []string) error { if _, ok := foreign[res.Name]; ok { // Leaving this here for now, warn about downgrades later - if int64(res.LastModified) > foreign[res.Name].BuildDate().Unix() { + if (!config.YayConf.TimeUpdate && (int64(res.LastModified) > foreign[res.Name].BuildDate().Unix())) || + alpm.VerCmp(foreign[res.Name].Version(), res.Version) < 0 { buffer.WriteString(fmt.Sprintf("\x1b[1m\x1b[32m==>\x1b[33;1m %s: \x1b[0m%s \x1b[33;1m-> \x1b[0m%s\n", res.Name, foreign[res.Name].Version(), res.Version)) outdated = append(outdated, res) @@ -187,8 +188,18 @@ func Upgrade(flags []string) error { return nil } + var finalmdeps []string for _, pkgi := range outdated { - PkgInstall(&pkgi, flags) + mdeps, err := PkgInstall(&pkgi, flags) + finalmdeps = append(finalmdeps, mdeps...) + if err != nil { + fmt.Println(err) + } + } + + err = pacman.CleanRemove(finalmdeps) + if err != nil { + fmt.Println(err) } return nil diff --git a/config/config.go b/config/config.go index b566b105..f6b914ad 100644 --- a/config/config.go +++ b/config/config.go @@ -38,6 +38,7 @@ type Configuration struct { SearchMode int `json:"-"` SortMode int `json:"sortmode"` TarBin string `json:"tarbin"` + TimeUpdate bool `json:"versionupdate"` } // YayConf holds the current config values for yay. @@ -123,6 +124,7 @@ func defaultSettings(config *Configuration) { config.PacmanConf = "/etc/pacman.conf" config.SortMode = BottomUp config.TarBin = "/usr/bin/bsdtar" + config.TimeUpdate = false } // Editor returns the preferred system editor. diff --git a/yay.go b/yay.go index 568421cb..14666d39 100644 --- a/yay.go +++ b/yay.go @@ -68,6 +68,8 @@ func parser() (op string, options []string, packages []string, changedConfig boo config.YayConf.Devel = true case "--nodevel": config.YayConf.Devel = false + case "--timeupdates": + config.YayConf.TimeUpdate = true case "--topdown": config.YayConf.SortMode = config.TopDown case "--complete":