-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.go
81 lines (67 loc) · 1.65 KB
/
exec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
"github.com/leonelquinteros/gotext"
"github.com/Jguer/yay/v10/pkg/settings"
"github.com/Jguer/yay/v10/pkg/text"
)
func sudoLoopBackground() {
updateSudo()
go sudoLoop()
}
func sudoLoop() {
for {
updateSudo()
time.Sleep(241 * time.Second)
}
}
func updateSudo() {
for {
err := config.Runtime.CmdRunner.Show(exec.Command(config.SudoBin, "-v"))
if err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
break
}
}
}
// waitLock will lock yay checking the status of db.lck until it does not exist
func waitLock(dbPath string) {
lockDBPath := filepath.Join(dbPath, "db.lck")
if _, err := os.Stat(lockDBPath); err != nil {
return
}
text.Warnln(gotext.Get("%s is present.", lockDBPath))
text.Warn(gotext.Get("There may be another Pacman instance running. Waiting..."))
for {
time.Sleep(3 * time.Second)
if _, err := os.Stat(lockDBPath); err != nil {
fmt.Println()
return
}
}
}
func passToPacman(args *settings.Arguments) *exec.Cmd {
argArr := make([]string, 0, 32)
if args.NeedRoot(config.Runtime) {
argArr = append(argArr, config.SudoBin)
argArr = append(argArr, strings.Fields(config.SudoFlags)...)
}
argArr = append(argArr, config.PacmanBin)
argArr = append(argArr, args.FormatGlobals()...)
argArr = append(argArr, args.FormatArgs()...)
if settings.NoConfirm {
argArr = append(argArr, "--noconfirm")
}
argArr = append(argArr, "--config", config.PacmanConf, "--")
argArr = append(argArr, args.Targets...)
if args.NeedRoot(config.Runtime) {
waitLock(config.Runtime.PacmanConf.DBPath)
}
return exec.Command(argArr[0], argArr[1:]...)
}