Replace !os.IsNotExist with == nil

!os.IsNotExist would also be true for other errors which don't mean the
file exists.
This commit is contained in:
Filippo Valsorda
2018-08-12 21:42:42 -04:00
parent 561c99875b
commit 5fc72d92bc
2 changed files with 7 additions and 7 deletions

View File

@@ -25,12 +25,12 @@ var (
func init() { func init() {
_, err := os.Stat("/etc/pki/ca-trust/source/anchors/") _, err := os.Stat("/etc/pki/ca-trust/source/anchors/")
if !os.IsNotExist(err) { if err == nil {
SystemTrustFilename = "/etc/pki/ca-trust/source/anchors/mkcert-rootCA.pem" SystemTrustFilename = "/etc/pki/ca-trust/source/anchors/mkcert-rootCA.pem"
SystemTrustCommand = []string{"update-ca-trust", "extract"} SystemTrustCommand = []string{"update-ca-trust", "extract"}
} else { } else {
_, err = os.Stat("/usr/local/share/ca-certificates/") _, err = os.Stat("/usr/local/share/ca-certificates/")
if !os.IsNotExist(err) { if err == nil {
SystemTrustFilename = "/usr/local/share/ca-certificates/mkcert-rootCA.crt" SystemTrustFilename = "/usr/local/share/ca-certificates/mkcert-rootCA.crt"
SystemTrustCommand = []string{"update-ca-certificates"} SystemTrustCommand = []string{"update-ca-certificates"}
} }

View File

@@ -22,7 +22,7 @@ func init() {
"/Applications/Firefox Developer Edition.app", "/Applications/Firefox Developer Edition.app",
} { } {
_, err := os.Stat(path) _, err := os.Stat(path)
hasNSS = hasNSS || !os.IsNotExist(err) hasNSS = hasNSS || err == nil
} }
switch runtime.GOOS { switch runtime.GOOS {
@@ -34,7 +34,7 @@ func init() {
certutilPath = filepath.Join(strings.TrimSpace(string(out)), "bin", "certutil") certutilPath = filepath.Join(strings.TrimSpace(string(out)), "bin", "certutil")
_, err = os.Stat(certutilPath) _, err = os.Stat(certutilPath)
hasCertutil = !os.IsNotExist(err) hasCertutil = err == nil
case "linux": case "linux":
var err error var err error
@@ -90,7 +90,7 @@ func (m *mkcert) uninstallNSS() {
func (m *mkcert) forEachNSSProfile(f func(profile string)) (found int) { func (m *mkcert) forEachNSSProfile(f func(profile string)) (found int) {
profiles, _ := filepath.Glob(FirefoxProfile) profiles, _ := filepath.Glob(FirefoxProfile)
if _, err := os.Stat(nssDB); !os.IsNotExist(err) { if _, err := os.Stat(nssDB); err == nil {
profiles = append(profiles, nssDB) profiles = append(profiles, nssDB)
} }
if len(profiles) == 0 { if len(profiles) == 0 {
@@ -100,12 +100,12 @@ func (m *mkcert) forEachNSSProfile(f func(profile string)) (found int) {
if stat, err := os.Stat(profile); err != nil || !stat.IsDir() { if stat, err := os.Stat(profile); err != nil || !stat.IsDir() {
continue continue
} }
if _, err := os.Stat(filepath.Join(profile, "cert9.db")); !os.IsNotExist(err) { if _, err := os.Stat(filepath.Join(profile, "cert9.db")); err == nil {
f("sql:" + profile) f("sql:" + profile)
found++ found++
continue continue
} }
if _, err := os.Stat(filepath.Join(profile, "cert8.db")); !os.IsNotExist(err) { if _, err := os.Stat(filepath.Join(profile, "cert8.db")); err == nil {
f("dbm:" + profile) f("dbm:" + profile)
found++ found++
} }