Repository navigation
fix(api): show symlinked directories in folder browser - #257
Conversation
os.ReadDir reports lstat semantics, so a symlink pointing at a directory has IsDir() == false and was silently dropped by HandleBrowse. Library folders reached through directory symlinks (e.g. a Docker bind mount whose entries link into a FUSE mount) never appeared in the folder picker even though the targets were valid and browsable. Resolve non-directory entries with os.Stat to follow the link and include them when the target is a directory; entries whose target cannot be stat'd (broken or looping links) are skipped rather than erroring the request. Regular directories keep the lstat fast path and take no extra syscall. Closes #208 Co-Authored-By: Claude Opus 4.8 <[email protected]>
📝 WalkthroughWalkthroughThe folder browse handler now follows directory symlinks instead of filtering solely on ChangesSymlink-aware directory browsing
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant HandleBrowse
participant Filesystem
participant OSStat
Client->>HandleBrowse: GET browse request
HandleBrowse->>Filesystem: ReadDir(cleaned)
Filesystem-->>HandleBrowse: directory entries
loop each entry
HandleBrowse->>HandleBrowse: check entry.IsDir()
alt not a directory
HandleBrowse->>HandleBrowse: check symlink mode
alt is symlink
HandleBrowse->>OSStat: Stat(full path)
OSStat-->>HandleBrowse: target info or error
alt target is directory
HandleBrowse->>HandleBrowse: include entry
else broken/non-dir
HandleBrowse->>HandleBrowse: skip entry
end
else not symlink
HandleBrowse->>HandleBrowse: skip entry
end
else is directory
HandleBrowse->>HandleBrowse: include entry
end
end
HandleBrowse-->>Client: JSON response with entries
Related issues: Suggested labels: bug, backend, filesystem Suggested reviewers: none identified from context 🐇 A symlink hopped, once left in the dark, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/api/handlers/filesystem.go`:
- Around line 67-72: In the filesystem entry filtering logic inside the
directory-walking code in internal/api/handlers/filesystem.go, handle entries
with unknown dirent types before checking symlinks, because entry.Type() can be
zero on FUSE/rclone mounts and valid directory symlinks may be skipped. Update
the branch around the entry.IsDir()/entry.Type() check to fall back to
entry.Info() or os.Lstat when Type()==0, then use that metadata to decide
whether the entry is a symlink to a directory. Keep the fix localized to the
directory scan path that processes entry, full, and target.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 16885a21-5517-45bf-ba4a-8472f01a6c57
📒 Files selected for processing (2)
internal/api/handlers/filesystem.gointernal/api/handlers/filesystem_test.go
| if !entry.IsDir() { | ||
| continue | ||
| if entry.Type()&os.ModeSymlink == 0 { | ||
| continue | ||
| } | ||
| target, err := os.Stat(full) | ||
| if err != nil || !target.IsDir() { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect declared Go toolchain and the symlink filtering branch without running repo code.
set -eu
echo "Declared Go toolchain files:"
fd -a '^(go\.mod|\.go-version|toolchain)$' . -x sh -c 'echo "--- $1"; sed -n "1,80p" "$1"' sh {}
echo
echo "HandleBrowse symlink filtering:"
sed -n '57,75p' internal/api/handlers/filesystem.goRepository: Silo-Server/silo-server
Length of output: 4552
🏁 Script executed:
#!/bin/bash
set -eu
echo "Relevant filesystem handler context:"
sed -n '1,170p' internal/api/handlers/filesystem.go
echo
echo "Search for symlink / browse handling elsewhere:"
rg -n "ModeSymlink|os\\.Stat\\(|os\\.Lstat\\(|ReadDir\\(|filesystemBrowseEntry|rclone|FUSE|symlink" internal -SRepository: Silo-Server/silo-server
Length of output: 15339
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
import os
import sys
# Probe Go stdlib docs availability is not possible, so just record that we're
# not executing repo code here; this script is only for source inspection once
# output returns.
PYRepository: Silo-Server/silo-server
Length of output: 161
🏁 Script executed:
#!/bin/bash
set -eu
echo "Open the exact function with line numbers:"
nl -ba internal/api/handlers/filesystem.go | sed -n '55,95p'
echo
echo "Search for comments/tests about symlink folders:"
rg -n "symlinked folders|symlink to a directory|broken or looping|DT_UNKNOWN|DirEntry" . -SRepository: Silo-Server/silo-server
Length of output: 1282
🌐 Web query:
rclone FUSE directory read symlink file type DT_UNKNOWN os.ReadDir symlink ModeSymlink
💡 Result:
When using rclone with FUSE mounts, symbolic links are handled through a specific translation layer because most cloud storage backends do not natively support them [1][2]. Rclone typically stores symlinks as regular files with a.rclonelink extension, containing the target path [1][2]. Regarding the FUSE directory read process and DT_UNKNOWN: 1. FUSE Dirent Types: When rclone's FUSE mount reads a directory (using methods like ReadDirAll), it must explicitly set the file type in the fuse.Dirent structure [3]. If the type is not explicitly set or recognized, FUSE may default to DT_UNKNOWN, which signals to the kernel that the actual file type is unknown and must be determined later, typically by performing a stat/lstat call on the file [4]. 2. Handling Symlinks in ReadDir: To correctly display symlinks as links in the mount, rclone implementations must identify these nodes (e.g., by checking the.rclonelink suffix or the VFS node type) and manually set the dirent.Type to fuse.DT_Link [3][5][4]. Recent improvements in rclone have addressed cases where this was missed in certain mount implementations, ensuring that symlinks are correctly identified during directory listings rather than defaulting to generic file types or DT_UNKNOWN [4]. 3. os.ReadDir and ModeSymlink: In Go, os.ReadDir (and the underlying directory reading mechanisms) often returns file entries where the type information is retrieved from the directory entry (d_type) [6]. When a symlink is encountered, checking the entry's mode requires identifying the os.ModeSymlink bit [7][8]. A common source of confusion is that os.ReadDir performs an lstat, meaning the resulting os.DirEntry reports the symlink itself (not its target) [9]. If software incorrectly assumes a directory listing provides complete type information, or if it encounters DT_UNKNOWN from the filesystem, it must follow up with a dedicated stat or lstat call to retrieve the correct os.FileMode and verify the os.ModeSymlink flag [10][4]. In summary, if you are observing DT_UNKNOWN or issues with symlink detection in an rclone FUSE mount, it is often due to the FUSE driver needing explicit instruction to flag those specific nodes as links during the directory read operation, rather than relying on the default file type [3][4].
Citations:
- 1: https://github.com/rclone/rclone/blob/master/docs/content/commands/rclone_mount.md
- 2: Support for symlinks in mount / vfs rclone/rclone#6337
- 3: https://github.com/rclone/rclone/blob/63cfe260/cmd/mount/dir.go
- 4: feat: support symlink detection when reading directories rclone/rclone#8554
- 5: dinoboy197/rclone@bdcd0af
- 6: https://go.dev/src/os/dir_unix.go?m=text
- 7: https://go.dev/src/os/types.go
- 8: https://go.googlesource.com/go/+/ca571803a87968b280d74b03cbc820ecf68e069d/src/os/dir_darwin.go
- 9: ReadDir is not setting FileInfo up correctly for symlinks spf13/afero#284
- 10: os: add ReadDir method for lightweight directory reading golang/go#41467
🌐 Web query:
Go os.ReadDir DirEntry.Type ModeSymlink FUSE DT_UNKNOWN symbolic link
💡 Result:
When using Go's os.ReadDir, the DirEntry.Type method relies on the underlying filesystem's ability to report file types via directory entry structures (such as the d_type field in Unix-like systems) [1][2]. On filesystems like FUSE, NFS, or certain bind mounts, the filesystem may not provide the file type information, causing the kernel to return DT_UNKNOWN for entries [3][2][4]. In such cases, Go's os.DirEntry implementation generally returns 0 for Type when the underlying system reports DT_UNKNOWN [1][5]. Consequently, it will not return os.ModeSymlink even if the entry is actually a symbolic link, because the information is not present in the directory entry metadata [3][4]. To accurately identify whether an entry is a symbolic link when Type returns 0 or DT_UNKNOWN, you must perform an explicit filesystem stat operation [5][4]. This is typically done by using: 1. os.Lstat(path) (or fs.Lstat(fsys, path)): This will return file information without following the link, allowing you to check the mode bits for os.ModeSymlink [6][5]. 2. Alternative approaches: Some implementations (like those in runtimes for other languages) use fstatat with the AT_SYMLINK_NOFOLLOW flag to resolve the type efficiently only when needed [5][4]. In summary, Type is a lightweight method that reflects the metadata provided by the directory read operation; if that metadata is absent (DT_UNKNOWN), you must perform a separate lookup to verify the file's type [1][3][4].
Citations:
- 1: os: add ReadDir method for lightweight directory reading golang/go#41467
- 2: https://sourceware.org/glibc/manual/2.43/html_node/Directory-Entries.html
- 3: https://stackoverflow.com/questions/47078417/readdir-returning-dirent-with-d-type-dt-unknown-for-directories-and
- 4: fix: handle DT_UNKNOWN in dir_iterator for bind-mounted filesystems oven-sh/bun#25838
- 5: fix(install): resolve DT_UNKNOWN entries on NFS/FUSE filesystems oven-sh/bun#27008
- 6: https://go.dev/src/os/types.go
🏁 Script executed:
#!/bin/bash
set -eu
echo "filesystem.go around browse logic:"
nl -ba internal/api/handlers/filesystem.go | sed -n '1,180p'
echo
echo "Any similar symlink handling in repo:"
rg -n "Type\\(\\)\\&os\\.ModeSymlink|entry\\.Info\\(|os\\.Lstat\\(" internal -SRepository: Silo-Server/silo-server
Length of output: 1150
Handle unknown dirent types before filtering symlinks. internal/api/handlers/filesystem.go:68 On FUSE/rclone mounts that return DT_UNKNOWN, entry.Type() is 0 even for symlinks, so valid directory symlinks can be skipped here. Fall back to entry.Info() or os.Lstat when Type()==0.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/api/handlers/filesystem.go` around lines 67 - 72, In the filesystem
entry filtering logic inside the directory-walking code in
internal/api/handlers/filesystem.go, handle entries with unknown dirent types
before checking symlinks, because entry.Type() can be zero on FUSE/rclone mounts
and valid directory symlinks may be skipped. Update the branch around the
entry.IsDir()/entry.Type() check to fall back to entry.Info() or os.Lstat when
Type()==0, then use that metadata to decide whether the entry is a symlink to a
directory. Keep the fix localized to the directory scan path that processes
entry, full, and target.
os.ReadDir reports lstat semantics, so a symlink pointing at a directory has IsDir() == false and was silently dropped by HandleBrowse. Library folders reached through directory symlinks (e.g. a Docker bind mount whose entries link into a FUSE mount) never appeared in the folder picker even though the targets were valid and browsable. Resolve non-directory entries with os.Stat to follow the link and include them when the target is a directory; entries whose target cannot be stat'd (broken or looping links) are skipped rather than erroring the request. Regular directories keep the lstat fast path and take no extra syscall. Closes Silo-Server#208 Co-authored-by: Claude Opus 4.8 <[email protected]>
Problem
The Browse Library Folders dialog silently omits directories reached through
symlinks (issue #208). Reported on a Docker setup where a bind mount contains
symlinks pointing into an rclone/FUSE mount: the symlinked show folders never
appear in the picker, even though they are valid and browsable inside the
container (and browsing works if the full symlink path is typed in manually).
Root cause:
HandleBrowseininternal/api/handlers/filesystem.gofiltersos.ReadDirentries withentry.IsDir().os.ReadDirreturnslstat-basedentries, so a symlink pointing at a directory reports
IsDir() == falseand wasdropped. (The browsed path itself already goes through
os.Stat, which followsthe link — which is exactly why typing the full symlink path worked but browsing
into its parent did not.)
Reproduced with a failing unit test against
HandleBrowse(tmpdir +os.Symlink): onmain, a directory symlink is absent from the response while areal subdirectory is present.
Approach
In the entry loop, when
entry.IsDir()is false, follow only symlink entries(
entry.Type()&os.ModeSymlink != 0) withos.Statand include them when theresolved target is a directory. Links whose target cannot be stat'd (broken or
looping) are skipped rather than erroring the whole request.
Ordinary regular files stay on the original no-stat fast path — this deliberately
does not stat every entry. Statting every non-directory would add thousands of
synchronous, potentially slow/hanging filesystem calls per request on large
FUSE/NAS-backed media roots (an admin-triggerable latency risk), for no functional
benefit since the fix only needs to follow symlinks. Directory entries keep the
lstatfast path and take no extra syscall.Verification
Commands run in an isolated worktree (
GOWORK=off,web/diststubbed for theembed directive):
GOWORK=off go build ./internal/... ./cmd/...→ OKmain(directory symlink missing) → green after the fix:GOWORK=off go test ./internal/api/handlers/ -run TestHandleBrowseFollowsDirectorySymlinksGOWORK=off go test ./internal/api/handlers/→ okgolangci-lint(v2) → no issues infilesystem.go/filesystem_test.gomake verify-local-paths→ cleanThe test covers: real dir included, directory symlink included (with correct
path), and regular file / file symlink / broken symlink all excluded.
Adversarial review
Codex adversarial review run against
main.needs-attention, medium): the first cut statted everynon-directory entry, adding an unbounded blocking stat pass over large media
folders. Fixed by statting only symlink-typed entries so regular files skip
the syscall.
the no-stat path, broken/looping links are skipped via
os.Staterrors, and nonew traversal boundary is introduced (the endpoint is already in the admin-only
router group, where arbitrary absolute paths were already browsable).
Risks & follow-up
Low risk; behavior for non-symlink entries is unchanged. Server-only fix for the
admin web folder picker (
FolderBrowser.tsx→GET /api/v1/.../filesystem/browse).The
silo-android/silo-appleclients do not consume this adminlibrary-setup endpoint, so no client follow-up is required. No API contract change
(additive behavior on an existing endpoint), no migration.
Closes #208
AI-use disclosure
Implemented by Claude Code (issue-to-pr skill) with human oversight.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests