peterbourgon / diskv

A disk-backed key-value store.
http://godoc.org/github.com/peterbourgon/diskv
MIT License
1.4k stars 102 forks source link

Write() errors with "no such file or directory" if key contains slashes #31

Closed riking closed 5 years ago

riking commented 8 years ago

To reproduce, simply attempt to store a value with a key of a URL and a transform function similar to:

func cacheDirTransform(key string) []string {
    fields, err := ParseURL(key)
    if err != nil {
        return []string{"_other", key}
    }
    return []string{fields.CategorySlug, fields.ArticleID}
}

edit: This also happens with no key transform and a key of fmt.Sprintf("%s/%s", categorySlug, articleID)

peterbourgon commented 8 years ago

This is documented in the README, albeit obliquely:

Note that your TransformFunc should ensure that one valid key doesn't transform to a subset of another valid key. That is, it shouldn't be possible to construct valid keys that resolve to directory names.

In other words, keys cannot contain os.PathSeparator.

PRs accepted to fix this somehow :)