mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +00:00
#15 plan implemented with 48h. To test
This commit is contained in:
parent
375f4d74de
commit
40f1743f42
1 changed files with 56 additions and 3 deletions
59
actions.go
59
actions.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue