Skip to content

Commit 4f19310

Browse files
Edit entry selected by fuzzy search (gopasspw#979)
Fixes gopasspw#957 Signed-off-by: Dominik Schulz <[email protected]>
1 parent b972ac0 commit 4f19310

File tree

9 files changed

+23
-22
lines changed

9 files changed

+23
-22
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ before_install:
99
- git config --global user.email [email protected]
1010

1111
go:
12-
- '1.10'
12+
- '1.11.x'
1313

1414
script:
1515
- make travis

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ codequality:
204204

205205
@echo -n " INTERFACER"
206206
@which interfacer > /dev/null; if [ $$? -ne 0 ]; then \
207-
$(GO) get mvdan.cc/interfacer; \
207+
$(GO) get -u mvdan.cc/interfacer; \
208208
fi
209209
@interfacer $(PKGS)
210210
@printf '%s\n' '$(OK)'

pkg/action/create/create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
func TestExtractHostname(t *testing.T) {
2323
for in, out := range map[string]string{
24-
"": "",
24+
"": "",
2525
"http://www.example.org/": "www.example.org",
2626
"++#+++#jhlkadsrezu 33 553q ++++##$§&": "jhlkadsrezu_33_553q",
2727
"www.example.org/?foo=bar#abc": "www.example.org",

pkg/action/edit.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (s *Action) Edit(ctx context.Context, c *cli.Context) error {
2727
ed := editor.Path(c)
2828

2929
// get existing content or generate new one from a template
30-
content, changed, err := s.editGetContent(ctx, name, c.Bool("create"))
30+
name, content, changed, err := s.editGetContent(ctx, name, c.Bool("create"))
3131
if err != nil {
3232
return err
3333
}
@@ -60,7 +60,7 @@ func (s *Action) Edit(ctx context.Context, c *cli.Context) error {
6060
return nil
6161
}
6262

63-
func (s *Action) editGetContent(ctx context.Context, name string, create bool) ([]byte, bool, error) {
63+
func (s *Action) editGetContent(ctx context.Context, name string, create bool) (string, []byte, bool, error) {
6464
if !s.Store.Exists(ctx, name) {
6565
newName := ""
6666
// capture only the name of the selected secret
@@ -77,17 +77,17 @@ func (s *Action) editGetContent(ctx context.Context, name string, create bool) (
7777
if s.Store.Exists(ctx, name) {
7878
sec, err := s.Store.Get(ctx, name)
7979
if err != nil {
80-
return nil, false, ExitError(ctx, ExitDecrypt, err, "failed to decrypt %s: %s", name, err)
80+
return name, nil, false, ExitError(ctx, ExitDecrypt, err, "failed to decrypt %s: %s", name, err)
8181
}
8282
content, err := sec.Bytes()
8383
if err != nil {
84-
return nil, false, ExitError(ctx, ExitDecrypt, err, "failed to decode %s: %s", name, err)
84+
return name, nil, false, ExitError(ctx, ExitDecrypt, err, "failed to decode %s: %s", name, err)
8585
}
86-
return content, false, nil
86+
return name, content, false, nil
8787
}
8888

8989
if !create {
90-
return nil, false, ExitError(ctx, ExitNotFound, nil, "entry not %s not found. Use --create to create a new entry with edit", name)
90+
return name, nil, false, ExitError(ctx, ExitNotFound, nil, "entry not %s not found. Use --create to create a new entry with edit", name)
9191
}
9292

9393
// new entry with template
@@ -99,9 +99,9 @@ func (s *Action) editGetContent(ctx context.Context, name string, create bool) (
9999
} else {
100100
fmt.Fprintf(stdout, "failed to execute template: %s\n", err)
101101
}
102-
return content, true, nil
102+
return name, content, true, nil
103103
}
104104

105105
// new entry, no template
106-
return nil, false, nil
106+
return name, nil, false, nil
107107
}

pkg/action/update_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ func TestUpdate(t *testing.T) {
6969
}()
7070
body := "foobar"
7171
hdr := &tar.Header{
72-
Name: "gopass",
73-
Mode: 0600,
74-
Size: int64(len(body)),
72+
Typeflag: tar.TypeReg,
73+
Name: "gopass",
74+
Mode: 0600,
75+
Size: int64(len(body)),
7576
}
7677
if err := tw.WriteHeader(hdr); err != nil {
7778
http.Error(w, "Internal Server Error", http.StatusInternalServerError)

pkg/backend/crypto/xc/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (x *XC) CreatePrivateKeyBatch(ctx context.Context, name, email, passphrase
126126
k.Identity.Name = name
127127
k.Identity.Email = email
128128
if err := x.secring.Set(k); err != nil {
129-
return errors.Wrapf(err, "failed to set %s to secring: %s", k, err)
129+
return errors.Wrapf(err, "failed to set %v to secring: %s", k, err)
130130
}
131131
return x.secring.Save()
132132
}

pkg/config/location_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
func TestPwStoreDirNoEnv(t *testing.T) {
1212
for in, out := range map[string]string{
13-
"": filepath.Join(Homedir(), ".password-store"),
14-
"work": filepath.Join(Homedir(), ".password-store-work"),
13+
"": filepath.Join(Homedir(), ".password-store"),
14+
"work": filepath.Join(Homedir(), ".password-store-work"),
1515
filepath.Join("foo", "bar"): filepath.Join(Homedir(), ".password-store-foo-bar"),
1616
} {
1717
assert.Equal(t, out, PwStoreDir(in))

pkg/fsutil/fsutil_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestCleanPath(t *testing.T) {
3232
}()
3333

3434
m := map[string]string{
35-
".": "",
35+
".": "",
3636
"/home/user/../bob/.password-store": "/home/bob/.password-store",
3737
"/home/user//.password-store": "/home/user/.password-store",
3838
tempdir + "/foo.gpg": tempdir + "/foo.gpg",

pkg/updater/update.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func extract(ctx context.Context, archive, dest string) error {
136136

137137
dfh, err := os.OpenFile(dest, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0755)
138138
if err != nil {
139-
return err
139+
return errors.Wrapf(err, "Failed to open file: %s", dest)
140140
}
141141
defer func() {
142142
_ = dfh.Close()
@@ -154,12 +154,12 @@ func extract(ctx context.Context, archive, dest string) error {
154154
break
155155
}
156156
if err != nil {
157-
return err
157+
return errors.Wrapf(err, "Failed to read from tar file")
158158
}
159159
name := filepath.Base(header.Name)
160-
if header.Typeflag == 0 && name == "gopass" {
160+
if header.Typeflag == tar.TypeReg && name == "gopass" {
161161
_, err := io.Copy(dfh, tarReader)
162-
return err
162+
return errors.Wrapf(err, "Failed to read gopass from tar file")
163163
}
164164
}
165165
return errors.Errorf("file not found in archive")

0 commit comments

Comments
 (0)