{"record":{"id":"f5b467aa98daa2e9","repo":"uutils/coreutils","slug":"mv-error-dangling-symlink","errorCode":null,"errorMessage":"mv-error-dangling-symlink","messagePattern":"mv-error-dangling-symlink","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/uu/mv/src/mv.rs","lineNumber":1124,"sourceCode":"    }\n    Err(io::Error::new(\n        io::ErrorKind::AlreadyExists,\n        \"could not allocate a unique temp name in destination directory\",\n    ))\n}\n\n#[cfg(windows)]\nfn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> {\n    let path_symlink_points_to = fs::read_link(from)?;\n    if path_symlink_points_to.exists() {\n        if path_symlink_points_to.is_dir() {\n            windows::fs::symlink_dir(&path_symlink_points_to, to)?;\n        } else {\n            windows::fs::symlink_file(&path_symlink_points_to, to)?;\n        }\n        fs::remove_file(from)\n    } else {\n        Err(io::Error::new(\n            io::ErrorKind::NotFound,\n            translate!(\"mv-error-dangling-symlink\"),\n        ))\n    }\n}\n\n#[cfg(target_os = \"wasi\")]\nfn rename_symlink_fallback(_from: &Path, _to: &Path) -> io::Result<()> {\n    Err(io::Error::other(translate!(\"mv-error-no-symlink-support\")))\n}\n\nfn rename_dir_fallback(\n    from: &Path,\n    to: &Path,\n    display_manager: Option<&MultiProgress>,\n    verbose: bool,\n    #[cfg(unix)] hardlink_tracker: Option<&mut HardlinkTracker>,\n    #[cfg(unix)] hardlink_scanner: Option<&HardlinkGroupScanner>,","sourceCodeStart":1106,"sourceCodeEnd":1142,"githubUrl":"https://github.com/uutils/coreutils/blob/85295bbf788bfd7a6926ba692031563504b304b7/src/uu/mv/src/mv.rs#L1106-L1142","documentation":"Raised by mv's rename_symlink_fallback (Windows path) when it must recreate a symlink at the destination but the source symlink itself is dangling — its target cannot be resolved, so `path_symlink_points_to` is None and mv refuses to guess. Instead of silently copying a broken link, it returns an io::Error with kind NotFound carrying this localized message. mv only reaches this fallback after a plain rename failed (e.g. cross-device), so the error surfaces mid-move.","triggerScenarios":"Calling `mv` on a symbolic link whose target does not exist, on a code path where the fast rename failed (cross-device move) and the fallback must reconstruct the link; on Windows the target resolution via symlink metadata returns None, hitting the else branch that constructs this error.","commonSituations":"Moving a symlink left behind by a deleted/uninstalled target; moving symlinks between filesystems where rename returns EXDEV; build or tmpfs setups where link targets live on another mount; Windows developer environments with NTFS symlinks whose targets were removed.","solutions":["Verify the symlink's target exists before moving: `readlink <link>` / `fs::read_link` and check the target path.","Recreate the symlink manually at the destination (`ln -s <target> <dest>`) and delete the source, bypassing the fallback.","If the dangling link is unwanted, delete it with `rm` instead of `mv`.","On Windows, ensure Developer Mode / symlink privileges are available and the target drive is mounted so resolution succeeds."],"exampleFix":"// before\nmv -f /mnt/a/link /mnt/b/link   // cross-device, dangling target -> NotFound\n// after\ntarget=$(readlink /mnt/a/link); [ -e \"$target\" ] || ln -s \"$target\" /mnt/b/link && rm /mnt/a/link","handlingStrategy":"validation","validationCode":"let target = std::fs::read_link(link)?;\nif !target.exists() {\n    eprintln!(\"dangling symlink: {} -> {}\", link.display(), target.display());\n    // remove instead of move, or fix target first\n}","typeGuard":"fn is_dangling(link: &Path) -> bool {\n    link.symlink_metadata().map(|m| m.is_symlink()).unwrap_or(false)\n        && link.metadata().is_err()\n}","tryCatchPattern":"match mv_result {\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        // dangling symlink: handle/remove explicitly\n    }\n    r => r?,\n}","preventionTips":["Check read_link + target existence before moving symlinks","Clean up dangling links with a periodic find -xtype l sweep","Avoid cross-device moves of symlinks; move targets and relink instead"],"tags":["mv","symlink","not-found","filesystem"],"backgroundTag":"dangling-symlink","analyzedSha":"85295bbf788bfd7a6926ba692031563504b304b7","analyzedAt":"2026-08-31T11:11:36.175Z","contentChangedAt":"2026-08-31T11:11:36.175Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}