Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions pass/pass_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ func (h Pass) Delete(serverURL string) error {
return err
}

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

return passDir
}

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

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

if _, err := os.Stat(path.Join(getPassDir(), PASS_FOLDER, encoded)); err != nil {
if os.IsNotExist(err) {
return "", "", nil;
}

return "", "", err
}

usernames, err := listPassDir(encoded)
if err != nil {
return "", "", err
Expand Down
10 changes: 7 additions & 3 deletions pass/pass_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ func TestPassHelper(t *testing.T) {
t.Fatal(err)
}

_, _, err = helper.Get(server)
if err == nil {
t.Fatalf("%s shuldn't exist any more", server)
username, _, err = helper.Get(server)
if err != nil {
t.Fatal(err)
}

if username != "" {
t.Fatalf("%s shouldn't exist any more", username)
}
}

Expand Down