mirror of
https://github.com/Jguer/yay
synced 2024-09-14 13:51:12 +00:00
#15 plan implemented with 48h. To test
This commit is contained in:
parent
375f4d74de
commit
40f1743f42
59
actions.go
59
actions.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
aur "github.com/jguer/yay/aur"
|
aur "github.com/jguer/yay/aur"
|
||||||
pac "github.com/jguer/yay/pacman"
|
pac "github.com/jguer/yay/pacman"
|
||||||
|
@ -328,14 +329,66 @@ func GetPkgbuild(pkg string) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Complete() (err error) {
|
func createAURList(path string) (err error) {
|
||||||
// Get the data
|
os.MkdirAll(os.Getenv("HOME")+"/.cache/yay", 0755)
|
||||||
|
|
||||||
|
out, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
resp, err := http.Get("https://aur.archlinux.org/packages.gz")
|
resp, err := http.Get("https://aur.archlinux.org/packages.gz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
_, err = io.Copy(os.Stdout, resp.Body)
|
_, err = io.Copy(out, resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateAURList(out io.Writer) (err error) {
|
||||||
|
resp, err := http.Get("https://aur.archlinux.org/packages.gz")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
_, err = io.Copy(out, resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Complete provides completion info for shells
|
||||||
|
func Complete() (err error) {
|
||||||
|
path := os.Getenv("HOME") + "/.cache/yay/aur.cache"
|
||||||
|
|
||||||
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
|
err = createAURList(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
in, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0755)
|
||||||
|
defer in.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := in.Stat()
|
||||||
|
if time.Since(info.ModTime()).Hours() > 48 {
|
||||||
|
err = updateAURList(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the data
|
||||||
|
_, err = io.Copy(os.Stdout, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue