Better NFS

This commit is contained in:
Melon 2021-12-24 01:46:59 +00:00
parent 2c3f84d527
commit d00e356bc2
Signed by: melon
GPG Key ID: B0ADD5395BCDAAB6

View File

@ -2,7 +2,7 @@ package neutered_filesystem
import ( import (
"net/http" "net/http"
"os" "path/filepath"
) )
type NeuteredFileSystem struct { type NeuteredFileSystem struct {
@ -13,18 +13,24 @@ func New(fs http.FileSystem) NeuteredFileSystem {
return NeuteredFileSystem{fs} return NeuteredFileSystem{fs}
} }
func (fs NeuteredFileSystem) Open(name string) (http.File, error) { func (nfs NeuteredFileSystem) Open(name string) (http.File, error) {
f, err := fs.fs.Open(name) f, err := nfs.fs.Open(name)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return neuteredReaddirFile{f}, nil
s, err := f.Stat()
if s.IsDir() {
index := filepath.Join(name, "index.html")
if _, err := nfs.fs.Open(index); err != nil {
closeErr := f.Close()
if closeErr != nil {
return nil, closeErr
} }
type neuteredReaddirFile struct { return nil, err
http.File }
} }
func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) { return f, nil
return nil, nil
} }