Skip to content

Commit d3d9934

Browse files
author
Vincent Demeester
authored
Merge pull request #84 from tych0/fix-helpers-protocol
return "" instead of an error when pass isn't present
2 parents 3c90bd2 + f212ea1 commit d3d9934

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
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

pass/pass_linux_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ func TestPassHelper(t *testing.T) {
5454
t.Fatal(err)
5555
}
5656

57-
_, _, err = helper.Get(server)
58-
if err == nil {
59-
t.Fatalf("%s shuldn't exist any more", server)
57+
username, _, err = helper.Get(server)
58+
if err != nil {
59+
t.Fatal(err)
60+
}
61+
62+
if username != "" {
63+
t.Fatalf("%s shouldn't exist any more", username)
6064
}
6165
}
6266

0 commit comments

Comments
 (0)