summaryrefslogtreecommitdiff
path: root/contrib/fs/file.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-05-03 13:21:34 -0600
committertjpcc <tjp@ctrl-c.club>2023-05-03 13:27:56 -0600
commite42716c43e0241e9d6d2ca7f7efe8d33a27127c2 (patch)
treece798c025bb7e9d9badecc23e96da0f876e212de /contrib/fs/file.go
parentbc8015c8803678d991de1d58cb407de100516d78 (diff)
hide private files from the FS
- ResolveFile acts like ErrNotFound - ResolveDirectory acts like ErrNotFound - RenderDirectoryListing strips out dot-prefixed entries
Diffstat (limited to 'contrib/fs/file.go')
-rw-r--r--contrib/fs/file.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/contrib/fs/file.go b/contrib/fs/file.go
index 591c1bd..d231466 100644
--- a/contrib/fs/file.go
+++ b/contrib/fs/file.go
@@ -15,6 +15,11 @@ import (
// returned.
func ResolveFile(request *sr.Request, fileSystem fs.FS) (string, fs.File, error) {
filepath := strings.TrimPrefix(request.Path, "/")
+
+ if isPrivate(filepath) {
+ return "", nil, nil
+ }
+
file, err := fileSystem.Open(filepath)
if isNotFound(err) {
return "", nil, nil
@@ -57,3 +62,12 @@ func mediaType(filePath string) string {
}
return mtype
}
+
+func isPrivate(fullpath string) bool {
+ for _, segment := range strings.Split(fullpath, "/") {
+ if len(segment) > 1 && segment[0] == '.' {
+ return true
+ }
+ }
+ return false
+}