Refactor: apply new internal structurs #206
|
@ -10,10 +10,10 @@ import (
|
|||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
git_transport "github.com/go-git/go-git/v5/plumbing/transport"
|
||||
gogit_http "github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||
gogit_ssh "github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
||||
|
@ -67,9 +67,9 @@ func GetAuthForURL(remoteURL *url.URL, httpUser, keyFile string) (auth git_trans
|
|||
|
||||
func readSSHPrivKey(keyFile string) (sig ssh.Signer, err error) {
|
||||
if keyFile != "" {
|
||||
keyFile, err = absPathWithExpansion(keyFile)
|
||||
keyFile, err = utils.AbsPathWithExpansion(keyFile)
|
||||
} else {
|
||||
keyFile, err = absPathWithExpansion("~/.ssh/id_rsa")
|
||||
keyFile, err = utils.AbsPathWithExpansion("~/.ssh/id_rsa")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -104,17 +104,3 @@ func promptPass(domain string) (string, error) {
|
|||
pass, err := terminal.ReadPassword(0)
|
||||
return string(pass), err
|
||||
}
|
||||
|
||||
func absPathWithExpansion(p string) (string, error) {
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if p == "~" {
|
||||
return u.HomeDir, nil
|
||||
} else if strings.HasPrefix(p, "~/") {
|
||||
return filepath.Join(u.HomeDir, p[2:]), nil
|
||||
} else {
|
||||
return filepath.Abs(p)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ package utils
|
|||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PathExists returns whether the given file or directory exists or not
|
||||
|
@ -35,3 +38,18 @@ func FileExist(fileName string) (bool, error) {
|
|||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AbsPathWithExpansion expand path beginning with "~/" to absolute path
|
||||
func AbsPathWithExpansion(p string) (string, error) {
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if p == "~" {
|
||||
return u.HomeDir, nil
|
||||
} else if strings.HasPrefix(p, "~/") {
|
||||
return filepath.Join(u.HomeDir, p[2:]), nil
|
||||
} else {
|
||||
return filepath.Abs(p)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user