From 13eae4b4af8eff150d5af869c4f20c3c50892e9f Mon Sep 17 00:00:00 2001 From: Dominik Schulz Date: Sat, 24 Feb 2018 21:54:02 +0100 Subject: [PATCH] Also check Path if GPG4Win install location is not found (#681) Fixes #647 --- backend/crypto/gpg/cli/gpg_windows.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/crypto/gpg/cli/gpg_windows.go b/backend/crypto/gpg/cli/gpg_windows.go index bbb2b4404d..d399a8337d 100644 --- a/backend/crypto/gpg/cli/gpg_windows.go +++ b/backend/crypto/gpg/cli/gpg_windows.go @@ -3,6 +3,7 @@ package cli import ( + "os/exec" "path/filepath" "github.com/justwatchcom/gopass/utils/fsutil" @@ -14,19 +15,27 @@ func detectBinaryCandidates(bin string) ([]string, error) { // gpg.exe for GPG4Win 3.0.0; would be gpg2.exe for 2.x bins := make([]string, 0, 4) - // try to detect location + // try to detect location of installed GPG4Win k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\GnuPG`, registry.QUERY_VALUE|registry.WOW64_32KEY) if err != nil { return bins, err } - v, _, err := k.GetStringValue("Install Directory") - if err != nil { - return bins, err + if v, _, err := k.GetStringValue("Install Directory"); err == nil && v != "" { + for _, b := range []string{bin, "gpg2.exe", "gpg.exe"} { + gpgPath := filepath.Join(v, "bin", b) + if fsutil.IsFile(gpgPath) { + bins = append(bins, gpgPath) + } + } } + // try to detect location for GPG installed somewhere on the PATH for _, b := range []string{bin, "gpg2.exe", "gpg.exe"} { - gpgPath := filepath.Join(v, "bin", b) + gpgPath, err := exec.LookPath(b) + if err != nil { + continue + } if fsutil.IsFile(gpgPath) { bins = append(bins, gpgPath) }