ErrorKind::FilesystemLoop
RustERRORNotableI/O

Filesystem loop detected

Quick Answer

Avoid following symlinks unconditionally; use symlink_metadata to detect links.

What this means

A symbolic link loop was encountered during path resolution.

Why it happens
  1. 1Symlink A → B → A forms a cycle
  2. 2Over-zealous symlink creation in automated scripts

Fix

Detect symlinks before following

Detect symlinks before following
use std::fs;
let meta = fs::symlink_metadata("path")?;
if meta.file_type().is_symlink() {
    let target = fs::read_link("path")?;
    println!("symlink -> {:?}", target);
}

Why this works

symlink_metadata reads link metadata without following it, avoiding loops.

Code examples
Noterust
// Maps to ELOOP on Linux; added in Rust 1.83
Same error in other languages
Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Rust errors