Skip to content

Commit

Permalink
Post-review fixes for hashicorp#1964
Browse files Browse the repository at this point in the history
  • Loading branch information
vespian committed Oct 5, 2016
1 parent 7608d21 commit 7d8b638
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions physical/file.go
Expand Up @@ -34,6 +34,10 @@ func newFileBackend(conf map[string]string) (Backend, error) {
}

func (b *FileBackend) Delete(path string) error {
if path == "" {
return nil
}

b.l.Lock()
defer b.l.Unlock()

Expand All @@ -42,7 +46,7 @@ func (b *FileBackend) Delete(path string) error {

err := os.Remove(fullPath)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("Failed to remove `%s`: %v", fullPath, err)
return fmt.Errorf("Failed to remove %q: %v", fullPath, err)
}

err = b.cleanupLogicalPath(path)
Expand All @@ -53,9 +57,9 @@ func (b *FileBackend) Delete(path string) error {
// cleanupLogicalPath is used to remove all empty nodes, begining with deepest
// one, aborting on first non-empty one, up to top-level node.
func (b *FileBackend) cleanupLogicalPath(path string) error {
nodes := strings.Split(path, "/")
nodes := strings.Split(path, fmt.Sprintf("%c", os.PathSeparator))
for i := len(nodes) - 1; i > 0; i-- {
fullPath := b.Path + "/" + strings.Join(nodes[:i], "/")
fullPath := filepath.Join(b.Path, filepath.Join(nodes[:i]...))

dir, err := os.Open(fullPath)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions physical/zookeeper.go
Expand Up @@ -238,13 +238,17 @@ func (c *ZookeeperBackend) Get(key string) (*Entry, error) {
func (c *ZookeeperBackend) Delete(key string) error {
defer metrics.MeasureSince([]string{"zookeeper", "delete"}, time.Now())

if key == "" {
return nil
}

// Delete the full path
fullPath := c.nodePath(key)
err := c.client.Delete(fullPath, -1)

// Mask if the node does not exist
if err != nil && err != zk.ErrNoNode {
return fmt.Errorf("Failed to remove `%s`: %v", fullPath, err)
return fmt.Errorf("Failed to remove %q: %v", fullPath, err)
}

err = c.cleanupLogicalPath(key)
Expand Down Expand Up @@ -281,7 +285,7 @@ func (c *ZookeeperBackend) List(prefix string) ([]string, error) {
// and append the slash which is what Vault depends on
// for iteration
if stat.DataLength > 0 && stat.NumChildren > 0 {
msgFmt := "Node %s is both of data and leaf type ??"
msgFmt := "Node %q is both of data and leaf type ??"
panic(fmt.Sprintf(msgFmt, childPath))
} else if stat.DataLength == 0 {
// No, we cannot differentiate here on number of children as node
Expand Down

0 comments on commit 7d8b638

Please sign in to comment.