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 (
"net/http"
"os"
"path/filepath"
)
type NeuteredFileSystem struct {
@ -13,18 +13,24 @@ func New(fs http.FileSystem) NeuteredFileSystem {
return NeuteredFileSystem{fs}
}
func (fs NeuteredFileSystem) Open(name string) (http.File, error) {
f, err := fs.fs.Open(name)
func (nfs NeuteredFileSystem) Open(name string) (http.File, error) {
f, err := nfs.fs.Open(name)
if err != nil {
return nil, err
}
return neuteredReaddirFile{f}, nil
}
type neuteredReaddirFile struct {
http.File
}
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
}
func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) {
return nil, nil
return nil, err
}
}
return f, nil
}