Skip to content

Commit

Permalink
Fixed pathes under windows (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Smaug authored and dominikschulz committed Oct 27, 2017
1 parent 7199e13 commit e9c3a28
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
34 changes: 22 additions & 12 deletions store/root/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"testing"

"path"

"github.com/justwatchcom/gopass/config"
"github.com/justwatchcom/gopass/store/sub"
)
Expand Down Expand Up @@ -59,7 +61,7 @@ func TestListMulti(t *testing.T) {
}()

// root store
_, ents, err := createStore(filepath.Join(tempdir, "root"))
_, ents, err := createStore(path.Join(tempdir, "root"))
if err != nil {
t.Fatalf("Failed to init root store: %s", err)
}
Expand All @@ -70,7 +72,7 @@ func TestListMulti(t *testing.T) {
t.Fatalf("Failed to init sub1 store: %s", err)
}
for _, k := range sub1Ent {
ents = append(ents, filepath.Join("sub1",k))
ents = append(ents, path.Join("sub1", k))
}

// sub2 store
Expand All @@ -79,7 +81,7 @@ func TestListMulti(t *testing.T) {
t.Fatalf("Failed to init sub2 store: %s", err)
}
for _, k := range sub2Ent {
ents = append(ents, filepath.Join("sub2", k))
ents = append(ents, path.Join("sub2", k))
}
sort.Strings(ents)

Expand All @@ -94,10 +96,10 @@ func TestListMulti(t *testing.T) {
if err != nil {
t.Fatalf("failed to create root store: %s", err)
}
if err := rs.AddMount(ctx, "sub1", filepath.Join(tempdir,"sub1")); err != nil {
if err := rs.AddMount(ctx, "sub1", filepath.Join(tempdir, "sub1")); err != nil {
t.Fatalf("failed to add mount %s: %s", "sub1", err)
}
if err := rs.AddMount(ctx, "sub2", filepath.Join(tempdir,"sub2")); err != nil {
if err := rs.AddMount(ctx, "sub2", filepath.Join(tempdir, "sub2")); err != nil {
t.Fatalf("failed to add mount %s: %s", "sub2", err)
}
tree, err := rs.Tree()
Expand Down Expand Up @@ -128,23 +130,23 @@ func TestListNested(t *testing.T) {
t.Fatalf("Failed to init sub1 store: %s", err)
}
for _, k := range sub1Ent {
ents = append(ents, filepath.Join("sub1",k))
ents = append(ents, path.Join("sub1", k))
}
// sub2 store
_, sub2Ent, err := createStore(filepath.Join(tempdir, "sub2"))
if err != nil {
t.Fatalf("Failed to init sub2 store: %s", err)
}
for _, k := range sub2Ent {
ents = append(ents, filepath.Join("sub2", k))
ents = append(ents, path.Join("sub2", k))
}
// sub3 store
_, sub3Ent, err := createStore(filepath.Join(tempdir, "sub3"))
if err != nil {
t.Fatalf("Failed to init sub3 store: %s", err)
}
for _, k := range sub3Ent {
ents = append(ents, filepath.Join("sub2", "sub3", k))
ents = append(ents, path.Join("sub2", "sub3", k))
}
sort.Strings(ents)

Expand All @@ -162,7 +164,7 @@ func TestListNested(t *testing.T) {
if err := rs.AddMount(ctx, "sub2", filepath.Join(tempdir, "sub2")); err != nil {
t.Fatalf("failed to add mount %s: %s", "sub2", err)
}
if err := rs.AddMount(ctx, filepath.Join("sub2", "sub3"), filepath.Join(tempdir, "sub3")); err != nil {
if err := rs.AddMount(ctx, "sub2/sub3", filepath.Join(tempdir, "sub3")); err != nil {
t.Fatalf("failed to add mount %s: %s", "sub2", err)
}
tree, err := rs.Tree()
Expand All @@ -173,6 +175,14 @@ func TestListNested(t *testing.T) {
compareLists(t, ents, tree.List(0))
}

func allPathsToSlash(paths []string) []string {
r := make([]string, len(paths))
for i, p := range paths {
r[i] = filepath.ToSlash(p)
}
return r
}

func createStore(dir string) ([]string, []string, error) {
recipients := []string{
"0xDEADBEEF",
Expand All @@ -186,14 +196,14 @@ func createStore(dir string) ([]string, []string, error) {
for _, file := range list {
filename := filepath.Join(dir, file+".gpg")
if err := os.MkdirAll(filepath.Dir(filename), 0700); err != nil {
return recipients, list, err
return recipients, allPathsToSlash(list), err
}
if err := ioutil.WriteFile(filename, []byte{}, 0644); err != nil {
return recipients, list, err
return recipients, allPathsToSlash(list), err
}
}
err := ioutil.WriteFile(filepath.Join(dir, sub.GPGID), []byte(strings.Join(recipients, "\n")), 0600)
return recipients, list, err
return recipients, allPathsToSlash(list), err
}

func maxLenStr(l []string) string {
Expand Down
3 changes: 2 additions & 1 deletion utils/jsonapi/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package jsonapi
import (
"testing"

"github.com/justwatchcom/gopass/store/secret"
"path/filepath"

"github.com/justwatchcom/gopass/store/secret"
)

func TestGetUsername(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions utils/tree/simple/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package simple

import (
"bytes"
"path/filepath"
"strings"

"path"

"github.com/justwatchcom/gopass/utils/tree"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -97,7 +98,7 @@ func (f *Folder) list(prefix string, maxDepth, curDepth int) []string {
out = append(out, f.Folders[key].list(prefix, maxDepth, curDepth+1)...)
}
for _, key := range sortedFiles(f.Files) {
out = append(out, filepath.Join(prefix, f.Files[key].Name))
out = append(out, path.Join(prefix, f.Files[key].Name))
}
return out
}
Expand Down

0 comments on commit e9c3a28

Please sign in to comment.