diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-05-03 13:21:34 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-05-03 13:27:56 -0600 |
commit | e42716c43e0241e9d6d2ca7f7efe8d33a27127c2 (patch) | |
tree | ce798c025bb7e9d9badecc23e96da0f876e212de /contrib/fs/dir.go | |
parent | bc8015c8803678d991de1d58cb407de100516d78 (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/dir.go')
-rw-r--r-- | contrib/fs/dir.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/contrib/fs/dir.go b/contrib/fs/dir.go index bb2d933..69d17e9 100644 --- a/contrib/fs/dir.go +++ b/contrib/fs/dir.go @@ -24,6 +24,10 @@ func ResolveDirectory( path = "." } + if isPrivate(path) { + return "", nil, nil + } + file, err := fileSystem.Open(path) if isNotFound(err) { return "", nil, nil @@ -124,6 +128,13 @@ func dirlistNamespace(path string, dirFile fs.ReadDirFile, server sr.Server) (ma return nil, err } + for i := len(entries) - 1; i >= 0; i-- { + if strings.HasPrefix(entries[i].Name(), ".") { + copy(entries[i:], entries[i+1:]) + entries = entries[:len(entries)-1] + } + } + sort.Slice(entries, func(i, j int) bool { return entries[i].Name() < entries[j].Name() }) |