mirror of
https://github.com/Jguer/yay
synced 2024-08-31 13:49:28 +00:00
chore(su): prefer short form if
This commit is contained in:
parent
ffb17fd2e3
commit
adb74b9252
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -199,10 +200,19 @@ func Test_getPackageRepoURL(t *testing.T) {
|
||||||
func TestABSPKGBUILDRepo(t *testing.T) {
|
func TestABSPKGBUILDRepo(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
cmdRunner := &testRunner{}
|
cmdRunner := &testRunner{}
|
||||||
|
want := "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch -b packages/linux https://github.com/archlinux/svntogit-packages.git linux"
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
ld := "systemd-run"
|
||||||
|
if path, _ := exec.LookPath(ld); path != "" {
|
||||||
|
ld = path
|
||||||
|
}
|
||||||
|
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch -b packages/linux https://github.com/archlinux/svntogit-packages.git linux", ld)
|
||||||
|
}
|
||||||
|
|
||||||
cmdBuilder := &testGitBuilder{
|
cmdBuilder := &testGitBuilder{
|
||||||
index: 0,
|
index: 0,
|
||||||
test: t,
|
test: t,
|
||||||
want: "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch -b packages/linux https://github.com/archlinux/svntogit-packages.git linux",
|
want: want,
|
||||||
parentBuilder: &exe.CmdBuilder{
|
parentBuilder: &exe.CmdBuilder{
|
||||||
Runner: cmdRunner,
|
Runner: cmdRunner,
|
||||||
GitBin: "/usr/local/bin/git",
|
GitBin: "/usr/local/bin/git",
|
||||||
|
@ -224,11 +234,20 @@ func TestABSPKGBUILDRepoExistsPerms(t *testing.T) {
|
||||||
|
|
||||||
os.MkdirAll(filepath.Join(dir, "linux", ".git"), 0o777)
|
os.MkdirAll(filepath.Join(dir, "linux", ".git"), 0o777)
|
||||||
|
|
||||||
|
want := fmt.Sprintf("/usr/local/bin/git --no-replace-objects -C %s/linux pull --ff-only", dir)
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
ld := "systemd-run"
|
||||||
|
if path, _ := exec.LookPath(ld); path != "" {
|
||||||
|
ld = path
|
||||||
|
}
|
||||||
|
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C %s/linux pull --ff-only", ld, dir)
|
||||||
|
}
|
||||||
|
|
||||||
cmdRunner := &testRunner{}
|
cmdRunner := &testRunner{}
|
||||||
cmdBuilder := &testGitBuilder{
|
cmdBuilder := &testGitBuilder{
|
||||||
index: 0,
|
index: 0,
|
||||||
test: t,
|
test: t,
|
||||||
want: fmt.Sprintf("/usr/local/bin/git --no-replace-objects -C %s/linux pull --ff-only", dir),
|
want: want,
|
||||||
parentBuilder: &exe.CmdBuilder{
|
parentBuilder: &exe.CmdBuilder{
|
||||||
Runner: cmdRunner,
|
Runner: cmdRunner,
|
||||||
GitBin: "/usr/local/bin/git",
|
GitBin: "/usr/local/bin/git",
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -77,11 +78,20 @@ func TestGetAURPkgbuild(t *testing.T) {
|
||||||
// THEN a clone command should be formed
|
// THEN a clone command should be formed
|
||||||
func TestAURPKGBUILDRepo(t *testing.T) {
|
func TestAURPKGBUILDRepo(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
want := "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress https://aur.archlinux.org/yay-bin.git yay-bin"
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
ld := "systemd-run"
|
||||||
|
if path, _ := exec.LookPath(ld); path != "" {
|
||||||
|
ld = path
|
||||||
|
}
|
||||||
|
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C /tmp/doesnt-exist clone --no-progress https://aur.archlinux.org/yay-bin.git yay-bin", ld)
|
||||||
|
}
|
||||||
|
|
||||||
cmdRunner := &testRunner{}
|
cmdRunner := &testRunner{}
|
||||||
cmdBuilder := &testGitBuilder{
|
cmdBuilder := &testGitBuilder{
|
||||||
index: 0,
|
index: 0,
|
||||||
test: t,
|
test: t,
|
||||||
want: "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress https://aur.archlinux.org/yay-bin.git yay-bin",
|
want: want,
|
||||||
parentBuilder: &exe.CmdBuilder{
|
parentBuilder: &exe.CmdBuilder{
|
||||||
Runner: cmdRunner,
|
Runner: cmdRunner,
|
||||||
GitBin: "/usr/local/bin/git",
|
GitBin: "/usr/local/bin/git",
|
||||||
|
@ -103,11 +113,20 @@ func TestAURPKGBUILDRepoExistsPerms(t *testing.T) {
|
||||||
|
|
||||||
os.MkdirAll(filepath.Join(dir, "yay-bin", ".git"), 0o777)
|
os.MkdirAll(filepath.Join(dir, "yay-bin", ".git"), 0o777)
|
||||||
|
|
||||||
|
want := fmt.Sprintf("/usr/local/bin/git --no-replace-objects -C %s/yay-bin pull --ff-only", dir)
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
ld := "systemd-run"
|
||||||
|
if path, _ := exec.LookPath(ld); path != "" {
|
||||||
|
ld = path
|
||||||
|
}
|
||||||
|
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C %s/yay-bin pull --ff-only", ld, dir)
|
||||||
|
}
|
||||||
|
|
||||||
cmdRunner := &testRunner{}
|
cmdRunner := &testRunner{}
|
||||||
cmdBuilder := &testGitBuilder{
|
cmdBuilder := &testGitBuilder{
|
||||||
index: 0,
|
index: 0,
|
||||||
test: t,
|
test: t,
|
||||||
want: fmt.Sprintf("/usr/local/bin/git --no-replace-objects -C %s/yay-bin pull --ff-only", dir),
|
want: want,
|
||||||
parentBuilder: &exe.CmdBuilder{
|
parentBuilder: &exe.CmdBuilder{
|
||||||
Runner: cmdRunner,
|
Runner: cmdRunner,
|
||||||
GitBin: "/usr/local/bin/git",
|
GitBin: "/usr/local/bin/git",
|
||||||
|
|
|
@ -231,8 +231,7 @@ func NewConfig(version string) (*Configuration, error) {
|
||||||
|
|
||||||
newConfig.expandEnv()
|
newConfig.expandEnv()
|
||||||
|
|
||||||
errPE := newConfig.setPrivilegeElevator()
|
if errPE := newConfig.setPrivilegeElevator(); errPE != nil {
|
||||||
if errPE != nil {
|
|
||||||
return nil, errPE
|
return nil, errPE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,15 +139,13 @@ func (c *CmdBuilder) deElevateCommand(ctx context.Context, cmd *exec.Cmd) *exec.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
path, err := exec.LookPath(cmd.Args[0])
|
path, _ := exec.LookPath(cmd.Args[0])
|
||||||
if err != nil {
|
|
||||||
panic("path should have already been validated")
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdArgs = append(cmdArgs, path)
|
cmdArgs = append(cmdArgs, path)
|
||||||
cmdArgs = append(cmdArgs, cmd.Args[1:]...)
|
cmdArgs = append(cmdArgs, cmd.Args[1:]...)
|
||||||
|
|
||||||
systemdCmd := exec.CommandContext(ctx, "systemd-run", cmdArgs...)
|
systemdCmd := exec.CommandContext(ctx, "systemd-run", cmdArgs...)
|
||||||
|
systemdCmd.Dir = cmd.Dir
|
||||||
|
|
||||||
return systemdCmd
|
return systemdCmd
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue