Skip to content

fix(api): show symlinked directories in folder browser - #257

Merged
Quick104 merged 1 commit into
mainfrom
fix/issue-208-folder-browser-symlinked-dirs
Jul 1, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/issue-208-folder-browser-symlinked-dirs

Conversation

@Quick104

@Quick104 Quick104 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

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: HandleBrowse in internal/api/handlers/filesystem.go filters
os.ReadDir entries with entry.IsDir(). os.ReadDir returns lstat-based
entries, so a symlink pointing at a directory reports IsDir() == false and was
dropped. (The browsed path itself already goes through os.Stat, which follows
the 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): on main, a directory symlink is absent from the response while a
real subdirectory is present.

Approach

In the entry loop, when entry.IsDir() is false, follow only symlink entries
(entry.Type()&os.ModeSymlink != 0) with os.Stat and include them when the
resolved 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
lstat fast path and take no extra syscall.

Verification

Commands run in an isolated worktree (GOWORK=off, web/dist stubbed for the
embed directive):

  • GOWORK=off go build ./internal/... ./cmd/... → OK
  • New test red on main (directory symlink missing) → green after the fix:
    GOWORK=off go test ./internal/api/handlers/ -run TestHandleBrowseFollowsDirectorySymlinks
  • Full package suite: GOWORK=off go test ./internal/api/handlers/ → ok
  • golangci-lint (v2) → no issues in filesystem.go / filesystem_test.go
  • make verify-local-paths → clean

The 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.

  • Iteration 1 (needs-attention, medium): the first cut statted every
    non-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.
  • Iteration 2: approve, no material findings — confirmed regular files stay on
    the no-stat path, broken/looping links are skipped via os.Stat errors, and no
    new 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-apple clients do not consume this admin
library-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

    • Directory browsing now includes valid symlinks that point to directories.
    • Broken symlinks, file symlinks, and other non-directory entries are still excluded.
    • Listed items now show the correct path for directory symlinks.
  • Tests

    • Added coverage for browsing real directories, directory symlinks, file symlinks, and broken symlinks.

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]>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The folder browse handler now follows directory symlinks instead of filtering solely on entry.IsDir(). Non-directory entries are checked for symlink status and stat'd to confirm they resolve to a directory before inclusion. Response entry paths now use the resolved full path. A new test validates this behavior.

Changes

Symlink-aware directory browsing

Layer / File(s) Summary
Symlink resolution in browse handler
internal/api/handlers/filesystem.go
HandleBrowse now computes name/full for each entry, follows symlinks via os.Stat to check if they resolve to a directory before inclusion, and sets Path from the resolved full path instead of joining cleaned and name.
Test coverage for symlinked directories
internal/api/handlers/filesystem_test.go
New test creates a real directory, a symlink-to-directory, a regular file, a symlink-to-file, and a broken symlink, then asserts only the directory and valid directory symlink appear in the browse response.

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
Loading

Related issues: #208 (Folder browser does not show symlinked directories)

Suggested labels: bug, backend, filesystem

Suggested reviewers: none identified from context

🐇 A symlink hopped, once left in the dark,
Now Silo greets it, welcomes it stark.
Stat-checked and verified, the path made true,
Broken links skipped, only the real ones come through.
A hop, a stat, a folder shown anew!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: showing symlinked directories in the folder browser.
Linked Issues check ✅ Passed The code and tests implement #208 by listing symlinked directories that resolve to valid folders and skipping broken or file symlinks.
Out of Scope Changes check ✅ Passed The diff stays focused on the folder browser fix and its tests, with no unrelated changes visible.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-208-folder-browser-symlinked-dirs

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7d8f090 and 15b302b.

📒 Files selected for processing (2)
  • internal/api/handlers/filesystem.go
  • internal/api/handlers/filesystem_test.go

Comment on lines 67 to +72
if !entry.IsDir() {
continue
if entry.Type()&os.ModeSymlink == 0 {
continue
}
target, err := os.Stat(full)
if err != nil || !target.IsDir() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.go

Repository: 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 -S

Repository: 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.
PY

Repository: 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" . -S

Repository: 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:


🌐 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:


🏁 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 -S

Repository: 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.

@Quick104
Quick104 merged commit cb8c109 into main Jul 1, 2026
3 checks passed
@Quick104
Quick104 deleted the fix/issue-208-folder-browser-symlinked-dirs branch July 1, 2026 22:10
Quick104 added a commit to RXWatcher/silo-server that referenced this pull request Jul 10, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Folder browser does not show symlinked directories

1 participant