{"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":1077,"sourceCode":"    ))]\n    {\n        let _ = fsxattr::copy_xattrs_ignore_unsupported(from, to);\n    }\n    let _ = preserve_ownership(from, to);\n    fs::remove_file(from)\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":1059,"sourceCodeEnd":1095,"githubUrl":"https://github.com/uutils/coreutils/blob/92995feca29e324a7c559ede91db81c32d9f5d59/src/uu/mv/src/mv.rs#L1059-L1095","documentation":"`rename_symlink_fallback` re-creates a symlink at the destination and deletes the source link; if the original symlink is dangling (its target does not exist), the fallback cannot determine/recreate the target and raises this NotFound-kind error instead of moving a link pointing nowhere.","triggerScenarios":"`mv` with a dangling symlink as source (or a cross-filesystem rename falling back to symlink recreation) where `path_symlink_points_to` fails to resolve/stat.","commonSituations":"Moving directory trees that contain broken symlinks (deleted targets, mounts not yet present, typos in link targets), especially between filesystems where rename falls back.","solutions":["Recreate the symlink target before moving (`ln -s <correct-target> <link>` then mv)","Delete the dangling link if it is no longer needed (`rm <link>`)","Use `cp -a` / `tar` to copy the tree, which preserves dangling links, then remove the source","Fix the link targets (e.g. relative instead of absolute paths) before the move"],"exampleFix":"// before\nmv tree/ /otherfs/    # tree/link -> /mnt/old/target (missing)\n// after\nln -s /new/target tree/link && mv tree/ /otherfs/","handlingStrategy":"validation","validationCode":"# detect dangling links that mv will refuse to relocate across filesystems\nfind tree -xtype l -print   # lists broken symlinks","typeGuard":"fn is_dangling_link(p: &Path) -> bool {\n    p.is_symlink() && !p.exists()\n}","tryCatchPattern":"match mv_result {\n    Err(e) if e.to_string().contains(\"dangling symlink\") => {\n        eprintln!(\"fix or delete broken links in the source tree, then retry\");\n    }\n    r => r?,\n}","preventionTips":["Run `find -xtype l` before moving trees between filesystems","Use relative symlink targets so moves don't break them","Delete or repair dead links during cleanup passes","Prefer cp -a/tar for trees known to contain broken links"],"tags":["mv","symlink","cli"],"backgroundTag":"file-not-found","analyzedSha":"92995feca29e324a7c559ede91db81c32d9f5d59","analyzedAt":"2026-09-20T12:39:35.476Z","contentChangedAt":"2026-09-20T12:39:35.476Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}