func (d *dir) mkdir(name string) (*dir, error) {
	if name == "" {
		return nil, fmt.Errorf("invalid dirname")
	}
	_, ok := d.children[name]
	if ok {
		return nil, errExists
	}
	child := &dir{
		common: common{
			p:   path.Join(d.path(), name),
			mod: time.Now(),
		},
	}
	d.add(child)
	d.mod = time.Now()
	return child, nil
}
mkdir creates a child directory under d with the given name.
package inmemory
import (
	"fmt"
	"io"
	"path"
	"sort"
	"strings"
	"time"
)
var (
	errExists    = fmt.Errorf("exists")
	errNotExists = fmt.Errorf("notexists")
	errIsNotDir  = fmt.Errorf("notdir")
	errIsDir     = fmt.Errorf("isdir")
)
type node interface {
	name() string
	path() string
	isdir() bool
	modtime() time.Time
}
type dir struct {
	common
	children map[string]node
}
var _ node = &dir{}
func (d *dir) isdir() bool {
	return true
}
func (d *dir) add(n node) {
	if d.children == nil {
		d.children = make(map[string]node)
	}
	d.children[n.name()] = n
	d.mod = time.Now()
}
func (d *dir) find(q string) node {
	q = strings.Trim(q, "/")
	i := strings.Index(q, "/")
	if q == "" {
		return d
	}
	if i == 0 {
		panic("shouldn't happen, no root paths")
	}
	var component string
	if i < 0 {
		component = q
	} else {
		component = q[:i]
	}
	child, ok := d.children[component]
	if !ok {
		return d
	}
	if child.isdir() {
		q = q[i+1:]
		return child.(*dir).find(q)
	}
	return child
}
func (d *dir) list(p string) ([]string, error) {
	n := d.find(p)
	if n.path() != p {
		return nil, errNotExists
	}
	if !n.isdir() {
		return nil, errIsNotDir
	}
	var children []string
	for _, child := range n.(*dir).children {
		children = append(children, child.path())
	}
	sort.Strings(children)
	return children, nil
}
func (d *dir) mkfile(p string) (*file, error) {
	n := d.find(p)
	if n.path() == p {
		if n.isdir() {
			return nil, errIsDir
		}
		return n.(*file), nil
	}
	dirpath, filename := path.Split(p)
	n, err := d.mkdirs(dirpath)
	if err != nil {
		return nil, err
	}
	dd := n.(*dir)
	n = &file{
		common: common{
			p:   path.Join(dd.path(), filename),
			mod: time.Now(),
		},
	}
	dd.add(n)
	return n.(*file), nil
}
func (d *dir) mkdirs(p string) (*dir, error) {
	p = normalize(p)
	n := d.find(p)
	if !n.isdir() {
		return nil, errIsNotDir
	}
	if n.path() == p {
		return n.(*dir), nil
	}
	dd := n.(*dir)
	relative := strings.Trim(strings.TrimPrefix(p, n.path()), "/")
	if relative == "" {
		return dd, nil
	}
	components := strings.Split(relative, "/")
	for _, component := range components {
		d, err := dd.mkdir(component)
		if err != nil {
			return nil, err
		}
		dd = d
	}
	return dd, nil
}