#15 plan implemented with 48h. To test

This commit is contained in:
Jguer 2017-04-09 11:48:03 +01:00
parent 375f4d74de
commit 40f1743f42

View file

@ -10,6 +10,7 @@ import (
"os/exec"
"strconv"
"strings"
"time"
aur "github.com/jguer/yay/aur"
pac "github.com/jguer/yay/pacman"
@ -328,14 +329,66 @@ func GetPkgbuild(pkg string) (err error) {
return
}
func Complete() (err error) {
// Get the data
func createAURList(path string) (err error) {
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")
if err != nil {
return err
}
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 {
return err
}