mirror of
https://github.com/Jguer/yay.git
synced 2025-12-09 00:03:52 -05:00
File closure fixed on init
This commit is contained in:
parent
a46e6bfa7b
commit
58ab6fd06f
14
cmd.go
14
cmd.go
@ -86,12 +86,12 @@ func init() {
|
|||||||
// Save the default config if nothing is found
|
// Save the default config if nothing is found
|
||||||
config.saveConfig()
|
config.saveConfig()
|
||||||
} else {
|
} else {
|
||||||
file, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE, 0644)
|
cfile, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error reading config:", err)
|
fmt.Println("Error reading config:", err)
|
||||||
} else {
|
} else {
|
||||||
defer file.Close()
|
defer cfile.Close()
|
||||||
decoder := json.NewDecoder(file)
|
decoder := json.NewDecoder(cfile)
|
||||||
err = decoder.Decode(&config)
|
err = decoder.Decode(&config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Loading default Settings.\nError reading config:", err)
|
fmt.Println("Loading default Settings.\nError reading config:", err)
|
||||||
@ -105,10 +105,10 @@ func init() {
|
|||||||
////////////////
|
////////////////
|
||||||
updated = false
|
updated = false
|
||||||
|
|
||||||
file, err := os.OpenFile(vcsFile, os.O_RDWR|os.O_CREATE, 0644)
|
vfile, err := os.Open(vcsFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer file.Close()
|
defer vfile.Close()
|
||||||
decoder := json.NewDecoder(file)
|
decoder := json.NewDecoder(vfile)
|
||||||
_ = decoder.Decode(&savedInfo)
|
_ = decoder.Decode(&savedInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "-Qstats":
|
case "-Qstats":
|
||||||
err = localStatistics(version)
|
err = localStatistics()
|
||||||
case "-Ss", "-Ssq", "-Sqs":
|
case "-Ss", "-Ssq", "-Sqs":
|
||||||
if op == "-Ss" {
|
if op == "-Ss" {
|
||||||
config.SearchMode = Detailed
|
config.SearchMode = Detailed
|
||||||
|
|||||||
@ -41,7 +41,7 @@ type Configuration struct {
|
|||||||
Devel bool `json:"devel"`
|
Devel bool `json:"devel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var version = "2.201"
|
const version = "2.201"
|
||||||
|
|
||||||
// baseURL givers the AUR default address.
|
// baseURL givers the AUR default address.
|
||||||
const baseURL string = "https://aur.archlinux.org"
|
const baseURL string = "https://aur.archlinux.org"
|
||||||
|
|||||||
71
print.go
71
print.go
@ -178,3 +178,74 @@ func biggestPackages() {
|
|||||||
}
|
}
|
||||||
// Could implement size here as well, but we just want the general idea
|
// Could implement size here as well, but we just want the general idea
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// localStatistics prints installed packages statistics.
|
||||||
|
func localStatistics() error {
|
||||||
|
info, err := statistics()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, _, remoteNames, err := filterPackages()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("\n Yay version r%s\n", version)
|
||||||
|
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
||||||
|
fmt.Printf("\x1B[1;32mTotal installed packages: \x1B[0;33m%d\x1B[0m\n", info.Totaln)
|
||||||
|
fmt.Printf("\x1B[1;32mTotal foreign installed packages: \x1B[0;33m%d\x1B[0m\n", len(remoteNames))
|
||||||
|
fmt.Printf("\x1B[1;32mExplicitly installed packages: \x1B[0;33m%d\x1B[0m\n", info.Expln)
|
||||||
|
fmt.Printf("\x1B[1;32mTotal Size occupied by packages: \x1B[0;33m%s\x1B[0m\n", human(info.TotalSize))
|
||||||
|
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
||||||
|
fmt.Println("\x1B[1;32mTen biggest packages\x1B[0m")
|
||||||
|
biggestPackages()
|
||||||
|
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
||||||
|
|
||||||
|
var q aurQuery
|
||||||
|
var j int
|
||||||
|
for i := len(remoteNames); i != 0; i = j {
|
||||||
|
j = i - config.RequestSplitN
|
||||||
|
if j < 0 {
|
||||||
|
j = 0
|
||||||
|
}
|
||||||
|
qtemp, err := rpc.Info(remoteNames[j:i])
|
||||||
|
q = append(q, qtemp...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var outcast []string
|
||||||
|
for _, s := range remoteNames {
|
||||||
|
found := false
|
||||||
|
for _, i := range q {
|
||||||
|
if s == i.Name {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
outcast = append(outcast, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, res := range q {
|
||||||
|
if res.Maintainer == "" {
|
||||||
|
fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is orphaned.\x1b[0m\n", res.Name)
|
||||||
|
}
|
||||||
|
if res.OutOfDate != 0 {
|
||||||
|
fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is out-of-date in AUR.\x1b[0m\n", res.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, res := range outcast {
|
||||||
|
fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is not available in AUR.\x1b[0m\n", res)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
71
query.go
71
query.go
@ -175,77 +175,6 @@ func syncInfo(pkgS []string, flags []string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalStatistics returns installed packages statistics.
|
|
||||||
func localStatistics(version string) error {
|
|
||||||
info, err := statistics()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, _, _, remoteNames, err := filterPackages()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("\n Yay version r%s\n", version)
|
|
||||||
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
|
||||||
fmt.Printf("\x1B[1;32mTotal installed packages: \x1B[0;33m%d\x1B[0m\n", info.Totaln)
|
|
||||||
fmt.Printf("\x1B[1;32mTotal foreign installed packages: \x1B[0;33m%d\x1B[0m\n", len(remoteNames))
|
|
||||||
fmt.Printf("\x1B[1;32mExplicitly installed packages: \x1B[0;33m%d\x1B[0m\n", info.Expln)
|
|
||||||
fmt.Printf("\x1B[1;32mTotal Size occupied by packages: \x1B[0;33m%s\x1B[0m\n", human(info.TotalSize))
|
|
||||||
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
|
||||||
fmt.Println("\x1B[1;32mTen biggest packages\x1B[0m")
|
|
||||||
biggestPackages()
|
|
||||||
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
|
||||||
|
|
||||||
var q aurQuery
|
|
||||||
var j int
|
|
||||||
for i := len(remoteNames); i != 0; i = j {
|
|
||||||
j = i - config.RequestSplitN
|
|
||||||
if j < 0 {
|
|
||||||
j = 0
|
|
||||||
}
|
|
||||||
qtemp, err := rpc.Info(remoteNames[j:i])
|
|
||||||
q = append(q, qtemp...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var outcast []string
|
|
||||||
for _, s := range remoteNames {
|
|
||||||
found := false
|
|
||||||
for _, i := range q {
|
|
||||||
if s == i.Name {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
outcast = append(outcast, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, res := range q {
|
|
||||||
if res.Maintainer == "" {
|
|
||||||
fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is orphaned.\x1b[0m\n", res.Name)
|
|
||||||
}
|
|
||||||
if res.OutOfDate != 0 {
|
|
||||||
fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is out-of-date in AUR.\x1b[0m\n", res.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, res := range outcast {
|
|
||||||
fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is not available in AUR.\x1b[0m\n", res)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search handles repo searches. Creates a RepoSearch struct.
|
// Search handles repo searches. Creates a RepoSearch struct.
|
||||||
func queryRepo(pkgInputN []string) (s repoQuery, n int, err error) {
|
func queryRepo(pkgInputN []string) (s repoQuery, n int, err error) {
|
||||||
dbList, err := alpmHandle.SyncDbs()
|
dbList, err := alpmHandle.SyncDbs()
|
||||||
|
|||||||
2
vcs.go
2
vcs.go
@ -129,7 +129,7 @@ func saveVCSInfo() error {
|
|||||||
if err != nil || string(marshalledinfo) == "null" {
|
if err != nil || string(marshalledinfo) == "null" {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
in, err := os.OpenFile(vcsFile, os.O_RDWR|os.O_CREATE, 0755)
|
in, err := os.OpenFile(vcsFile, os.O_RDWR|os.O_CREATE, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user