mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +00:00
Added Save info to vcs
This commit is contained in:
parent
5c0650fe5a
commit
9f781c0411
4 changed files with 66 additions and 22 deletions
|
@ -98,18 +98,15 @@ func (a *Result) Install(flags []string) (finalmdeps []string, err error) {
|
|||
}
|
||||
dir := util.BaseDir + a.PackageBase + "/"
|
||||
|
||||
if _, err = os.Stat(dir); os.IsNotExist(err) {
|
||||
if err = util.DownloadAndUnpack(BaseURL+a.URLPath, util.BaseDir, false); err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if _, err = os.Stat(dir); os.IsExist(err) {
|
||||
if !util.ContinueTask("Directory exists. Clean Build?", "yY") {
|
||||
os.RemoveAll(util.BaseDir + a.PackageBase)
|
||||
}
|
||||
}
|
||||
|
||||
if err = util.DownloadAndUnpack(BaseURL+a.URLPath, util.BaseDir, false); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !util.ContinueTask("Edit PKGBUILD?", "yY") {
|
||||
editcmd := exec.Command(util.Editor(), dir+"PKGBUILD")
|
||||
|
|
|
@ -19,23 +19,24 @@ type branches []branch
|
|||
|
||||
// Info contains the last commit sha of a repo
|
||||
type Info struct {
|
||||
Package string `json:"owner"`
|
||||
Repo string `json:"Repo"`
|
||||
Package string `json:"pkgname"`
|
||||
URL string `json:"url"`
|
||||
SHA string `json:"sha"`
|
||||
}
|
||||
|
||||
type infos []Info
|
||||
|
||||
var savedInfo infos
|
||||
var configfile string
|
||||
|
||||
func init() {
|
||||
path := os.Getenv("HOME") + "/.config/yay/yay_github.json"
|
||||
configfile = os.Getenv("HOME") + "/.config/yay/yay_vcs.json"
|
||||
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
os.MkdirAll(os.Getenv("HOME")+"/.config/yay/yay_github.json", 0755)
|
||||
if _, err := os.Stat(configfile); os.IsNotExist(err) {
|
||||
_ = os.MkdirAll(os.Getenv("HOME")+"/.config/yay", 0755)
|
||||
}
|
||||
|
||||
file, err := os.Open(path)
|
||||
file, err := os.Open(configfile)
|
||||
if err != nil {
|
||||
fmt.Println("error:", err)
|
||||
return
|
||||
|
@ -47,7 +48,8 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
func parseSource(source string) (owner string, repo string) {
|
||||
// ParseSource returns owner and repo from source
|
||||
func ParseSource(source string) (owner string, repo string) {
|
||||
split := strings.Split(source, "github.com/")
|
||||
if len(split) > 1 {
|
||||
secondSplit := strings.Split(split[1], "/")
|
||||
|
@ -58,13 +60,44 @@ func parseSource(source string) (owner string, repo string) {
|
|||
repo = thirdSplit[0]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func checkUpdates() {
|
||||
func (info *Info) needsUpdate() bool {
|
||||
var newRepo branches
|
||||
r, err := http.Get(info.URL)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
defer r.Body.Close()
|
||||
|
||||
err = json.NewDecoder(r.Body).Decode(&newRepo)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
|
||||
for _, e := range newRepo {
|
||||
if e.Name == "master" {
|
||||
if e.SHA != info.SHA {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func CheckUpdates() (toUpdate []string) {
|
||||
for _, e := range savedInfo {
|
||||
if e.needsUpdate() {
|
||||
toUpdate = append(toUpdate, e.Package)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func inStore(pkgname string) *Info {
|
||||
|
@ -86,7 +119,7 @@ func BranchInfo(pkgname string, owner string, repo string) (err error) {
|
|||
}
|
||||
defer r.Body.Close()
|
||||
|
||||
json.NewDecoder(r.Body).Decode(newRepo)
|
||||
_ = json.NewDecoder(r.Body).Decode(&newRepo)
|
||||
|
||||
packinfo := inStore(pkgname)
|
||||
|
||||
|
@ -94,13 +127,28 @@ func BranchInfo(pkgname string, owner string, repo string) (err error) {
|
|||
if e.Name == "master" {
|
||||
if packinfo != nil {
|
||||
packinfo.Package = pkgname
|
||||
packinfo.Repo = owner + "/" + repo
|
||||
packinfo.URL = url
|
||||
packinfo.SHA = e.SHA
|
||||
} else {
|
||||
savedInfo = append(savedInfo, Info{Package: pkgname, Repo: owner + "/" + repo, SHA: e.SHA})
|
||||
savedInfo = append(savedInfo, Info{Package: pkgname, URL: url, SHA: e.SHA})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func SaveBranchInfo() error {
|
||||
marshalledinfo, _ := json.Marshal(savedInfo)
|
||||
in, err := os.OpenFile(configfile, os.O_RDWR|os.O_CREATE, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
_, err = in.Write(marshalledinfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = in.Sync()
|
||||
return err
|
||||
}
|
|
@ -29,5 +29,4 @@ func TestParsing(t *testing.T) {
|
|||
if ack.owner != "davidgiven" || ack.repo != "ack" {
|
||||
t.Fatalf("Expected to find davidgiven/ack, found %+v/%+v", ack.owner, ack.repo)
|
||||
}
|
||||
|
||||
}
|
2
utils.go
2
utils.go
|
@ -47,7 +47,7 @@ func Complete() (err error) {
|
|||
path := os.Getenv("HOME") + "/.cache/yay/aur_" + util.Shell + ".cache"
|
||||
|
||||
if info, err := os.Stat(path); os.IsNotExist(err) || time.Since(info.ModTime()).Hours() > 48 {
|
||||
os.MkdirAll(os.Getenv("HOME")+"/.cache/yay/aur_"+util.Shell+".cache", 0755)
|
||||
os.MkdirAll(os.Getenv("HOME")+"/.cache/yay/", 0755)
|
||||
|
||||
out, err := os.Create(path)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue