mirror of
https://github.com/FiloSottile/mkcert.git
synced 2025-10-13 16:31:41 +08:00
Cleanup path logics with pathExists and binaryExists
This commit is contained in:
@@ -46,24 +46,11 @@ func init() {
|
||||
SystemTrustFilename = "/usr/share/pki/trust/anchors/%s.pem"
|
||||
SystemTrustCommand = []string{"update-ca-certificates"}
|
||||
}
|
||||
if SystemTrustCommand != nil {
|
||||
_, err := exec.LookPath(SystemTrustCommand[0])
|
||||
if err != nil {
|
||||
SystemTrustCommand = nil
|
||||
}
|
||||
if SystemTrustCommand != nil && !binaryExists(SystemTrustCommand[0]) {
|
||||
SystemTrustCommand = nil
|
||||
}
|
||||
}
|
||||
|
||||
func pathExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func binaryExists(name string) bool {
|
||||
_, err := exec.LookPath(name)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (m *mkcert) systemTrustFilename() string {
|
||||
return fmt.Sprintf(SystemTrustFilename, strings.Replace(m.caUniqueName(), " ", "_", -1))
|
||||
}
|
||||
@@ -115,7 +102,7 @@ func (m *mkcert) uninstallPlatform() bool {
|
||||
}
|
||||
|
||||
func CommandWithSudo(cmd ...string) *exec.Cmd {
|
||||
if _, err := exec.LookPath("sudo"); err != nil {
|
||||
if !binaryExists("sudo") {
|
||||
return exec.Command(cmd[0], cmd[1:]...)
|
||||
}
|
||||
return exec.Command("sudo", append([]string{"--"}, cmd...)...)
|
||||
|
Reference in New Issue
Block a user