remove / prefix and close directories properly in query
remove / prefix and close directories properly in query

Backported from commit e965c53780003a01fcbd94af96333ace4b3e2748 in the
vendored copy in https://github.com/ipfs/go-ipfs

jbenet/go-datastore,rht/go-datastore,cryptix/go-datastore,whyrusleeping/datastore.go