Skip to content

Commit

Permalink
Merge pull request #3479 from hashicorp/issue-3476
Browse files Browse the repository at this point in the history
Allow underscores at the start of directories in file backend.
  • Loading branch information
jefferai authored Oct 26, 2017
2 parents bdd70ff + af1ae58 commit bc6631f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
12 changes: 9 additions & 3 deletions physical/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,16 @@ func (b *FileBackend) ListInternal(prefix string) ([]string, error) {
}

for i, name := range names {
if name[0] == '_' {
names[i] = name[1:]
} else {
fi, err := os.Stat(filepath.Join(path, name))
if err != nil {
return nil, err
}
if fi.IsDir() {
names[i] = name + "/"
} else {
if name[0] == '_' {
names[i] = name[1:]
}
}
}

Expand Down
61 changes: 61 additions & 0 deletions physical/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,66 @@ func TestFileBackend(t *testing.T) {
}

physical.ExerciseBackend(t, b)

// Underscores should not trip things up; ref GH-3476
e := &physical.Entry{Key: "_zip", Value: []byte("foobar")}
err = b.Put(e)
if err != nil {
t.Fatalf("err: %v", err)
}
e = &physical.Entry{Key: "_zip/_zap", Value: []byte("boofar")}
err = b.Put(e)
if err != nil {
t.Fatalf("err: %v", err)
}
e, err = b.Get("_zip/_zap")
if err != nil {
t.Fatalf("err: %v", err)
}
if e == nil {
t.Fatal("got nil entry")
}
vals, err := b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 2 || vals[0] == vals[1] {
t.Fatalf("bad: %v", vals)
}
for _, val := range vals {
if val != "_zip/" && val != "_zip" {
t.Fatalf("bad val: %v", val)
}
}
vals, err = b.List("_zip/")
if err != nil {
t.Fatal(err)
}
if len(vals) != 1 || vals[0] != "_zap" {
t.Fatalf("bad: %v", vals)
}
err = b.Delete("_zip/_zap")
if err != nil {
t.Fatal(err)
}
vals, err = b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 1 || vals[0] != "_zip" {
t.Fatalf("bad: %v", vals)
}
err = b.Delete("_zip")
if err != nil {
t.Fatal(err)
}
vals, err = b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 0 {
t.Fatalf("bad: %v", vals)
}

physical.ExerciseBackend_ListPrefix(t, b)
}

0 comments on commit bc6631f

Please sign in to comment.