afero
afero copied to clipboard
HttpFs.Dir doesn't work properly when given root path
If you try
httpFs := afero.NewHttpFs(<ExistingFS>)
fileserver := http.FileServer(httpFs.Dir("/")))
http.Handle("/", fileserver)
you'll find that your fileserver successfully lists the directory, but gives 404 on any file. However, if you do
httpFs := afero.NewHttpFs(<ExistingFS>)
fileserver := http.FileServer(httpFs.Dir("/something/")))
http.Handle("/", fileserver)
everything works as expected.
Similar bug for memory fs
package main
import "github.com/spf13/afero"
import "fmt"
func main() {
fass := afero.NewMemMapFs()
fass.Mkdir("/", 0755)
slash, _ := afero.DirExists(fass, "/")
fmt.Printf("%t\n", slash)
st, err := fass.Stat("/")
fmt.Printf("«%s»\n", st.Name())
fmt.Printf("err: %T\n", err)
}
os.Stat("/").Name() returns "/", but the memory file system returns ""
, which is very wrong.
Compare with the unix tool basename /
- which also returns / for slash and not ""
.