Skip to content

Commit 09e536a

Browse files
author
Tycho Andersen
committed
return "" instead of an error when pass isn't present
It turns out the cred helpers protocol is to return "" and not an error when a credential isn't present, so let's do that. Signed-off-by: Tycho Andersen <[email protected]>
1 parent 3c90bd2 commit 09e536a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

pass/pass_linux.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ func (h Pass) Delete(serverURL string) error {
111111
return err
112112
}
113113

114-
// listPassDir lists all the contents of a directory in the password store.
115-
// Pass uses fancy unicode to emit stuff to stdout, so rather than try
116-
// and parse this, let's just look at the directory structure instead.
117-
func listPassDir(args ...string) ([]os.FileInfo, error) {
114+
func getPassDir() string {
118115
passDir := os.ExpandEnv("$HOME/.password-store")
119116
for _, e := range os.Environ() {
120117
parts := strings.SplitN(e, "=", 2)
@@ -130,6 +127,14 @@ func listPassDir(args ...string) ([]os.FileInfo, error) {
130127
break
131128
}
132129

130+
return passDir
131+
}
132+
133+
// listPassDir lists all the contents of a directory in the password store.
134+
// Pass uses fancy unicode to emit stuff to stdout, so rather than try
135+
// and parse this, let's just look at the directory structure instead.
136+
func listPassDir(args ...string) ([]os.FileInfo, error) {
137+
passDir := getPassDir()
133138
p := path.Join(append([]string{passDir, PASS_FOLDER}, args...)...)
134139
contents, err := ioutil.ReadDir(p)
135140
if err != nil {
@@ -155,6 +160,14 @@ func (h Pass) Get(serverURL string) (string, string, error) {
155160

156161
encoded := base64.URLEncoding.EncodeToString([]byte(serverURL))
157162

163+
if _, err := os.Stat(path.Join(getPassDir(), PASS_FOLDER, encoded)); err != nil {
164+
if os.IsNotExist(err) {
165+
return "", "", nil;
166+
}
167+
168+
return "", "", err
169+
}
170+
158171
usernames, err := listPassDir(encoded)
159172
if err != nil {
160173
return "", "", err

0 commit comments

Comments
 (0)