diff options
author | Dave Henderson <[email protected]> | 2022-09-05 19:25:34 -0400 |
---|---|---|
committer | Dave Henderson <[email protected]> | 2022-09-05 19:25:34 -0400 |
commit | fded2644f8ddda33002353ee3aedd15195f17cb5 (patch) | |
tree | 76af0a9b2d9919f0682aee081d0ad6e9c7975fca /modules/caddyhttp/fileserver/staticfiles.go | |
parent | 487217519cd8dad207d04d5db966aacff3949b1d (diff) | |
download | caddy-fded2644f8ddda33002353ee3aedd15195f17cb5.tar.gz caddy-fded2644f8ddda33002353ee3aedd15195f17cb5.zip |
Drop requirement for filesystems to implement fs.StatFS
Signed-off-by: Dave Henderson <[email protected]>
Diffstat (limited to 'modules/caddyhttp/fileserver/staticfiles.go')
-rw-r--r-- | modules/caddyhttp/fileserver/staticfiles.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go index 25bcf5a26..0639d979f 100644 --- a/modules/caddyhttp/fileserver/staticfiles.go +++ b/modules/caddyhttp/fileserver/staticfiles.go @@ -83,14 +83,14 @@ type FileServer struct { // disk file system. // // File system modules used here must adhere to the following requirements: - // - Implement fs.StatFS interface. + // - Implement fs.FS interface. // - Support seeking on opened files; i.e.returned fs.File values must // implement the io.Seeker interface. This is required for determining // Content-Length and satisfying Range requests. // - fs.File values that represent directories must implement the // fs.ReadDirFile interface so that directory listings can be procured. FileSystemRaw json.RawMessage `json:"file_system,omitempty" caddy:"namespace=caddy.fs inline_key=backend"` - fileSystem fs.StatFS + fileSystem fs.FS // The path to the root of the site. Default is `{http.vars.root}` if set, // or current working directory otherwise. This should be a trusted value. @@ -175,7 +175,7 @@ func (fsrv *FileServer) Provision(ctx caddy.Context) error { if err != nil { return fmt.Errorf("loading file system module: %v", err) } - fsrv.fileSystem = mod.(fs.StatFS) + fsrv.fileSystem = mod.(fs.FS) } if fsrv.fileSystem == nil { fsrv.fileSystem = osFS{} @@ -244,7 +244,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c zap.String("result", filename)) // get information about the file - info, err := fsrv.fileSystem.Stat(filename) + info, err := fs.Stat(fsrv.fileSystem, filename) if err != nil { err = fsrv.mapDirOpenError(err, filename) if errors.Is(err, fs.ErrNotExist) { @@ -270,7 +270,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c continue } - indexInfo, err := fsrv.fileSystem.Stat(indexPath) + indexInfo, err := fs.Stat(fsrv.fileSystem, indexPath) if err != nil { continue } @@ -350,7 +350,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c continue } compressedFilename := filename + precompress.Suffix() - compressedInfo, err := fsrv.fileSystem.Stat(compressedFilename) + compressedInfo, err := fs.Stat(fsrv.fileSystem, compressedFilename) if err != nil || compressedInfo.IsDir() { fsrv.logger.Debug("precompressed file not accessible", zap.String("filename", compressedFilename), zap.Error(err)) continue @@ -490,7 +490,7 @@ func (fsrv *FileServer) mapDirOpenError(originalErr error, name string) error { if parts[i] == "" { continue } - fi, err := fsrv.fileSystem.Stat(strings.Join(parts[:i+1], separator)) + fi, err := fs.Stat(fsrv.fileSystem, strings.Join(parts[:i+1], separator)) if err != nil { return originalErr } @@ -613,13 +613,13 @@ func (wr statusOverrideResponseWriter) WriteHeader(int) { wr.ResponseWriter.WriteHeader(wr.code) } -// osFS is a simple fs.StatFS implementation that uses the local +// osFS is a simple fs.FS implementation that uses the local // file system. (We do not use os.DirFS because we do our own // rooting or path prefixing without being constrained to a single // root folder. The standard os.DirFS implementation is problematic // since roots can be dynamic in our application.) // -// osFS also implements fs.GlobFS, fs.ReadDirFS, and fs.ReadFileFS. +// osFS also implements fs.StatFS, fs.GlobFS, fs.ReadDirFS, and fs.ReadFileFS. type osFS struct{} func (osFS) Open(name string) (fs.File, error) { return os.Open(name) } @@ -640,6 +640,7 @@ var ( _ caddy.Provisioner = (*FileServer)(nil) _ caddyhttp.MiddlewareHandler = (*FileServer)(nil) + _ fs.StatFS = (*osFS)(nil) _ fs.GlobFS = (*osFS)(nil) _ fs.ReadDirFS = (*osFS)(nil) _ fs.ReadFileFS = (*osFS)(nil) |