{"record":{"id":"083d5e799f65c617","repo":"can1357/oh-my-pi","slug":"0-and-1-are-the-same-file","errorCode":null,"errorMessage":"{0} and {1} are the same file","messagePattern":"(.+?) and (.+?) are the same file","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/mv.rs","lineNumber":57,"sourceCode":"\t\tare_hardlinks_to_same_file, canonicalize, path_ends_with_terminator,\n\t},\n\tupdate_control::{self, UpdateMode},\n};\n\nuse crate::host::{Host, Utility, format_usage, matches_parser, util};\n#[cfg(unix)]\nuse self::hardlink::{\n\tHardlinkGroupScanner, HardlinkOptions, HardlinkTracker, create_hardlink_context,\n\twith_optional_hardlink_context,\n};\n\n#[derive(Debug, Error)]\nenum MvError {\n\t#[error(\"cannot stat {0}: No such file or directory\")]\n\tNoSuchFile(String),\n\t#[error(\"cannot stat {0}: Not a directory\")]\n\tCannotStatNotADirectory(String),\n\t#[error(\"{0} and {1} are the same file\")]\n\tSameFile(String, String),\n\t#[error(\"cannot move {0} to a subdirectory of itself, {1}\")]\n\tSelfTargetSubdirectory(String, String),\n\t#[error(\"cannot overwrite directory {0} with non-directory\")]\n\tDirectoryToNonDirectory(String),\n\t#[error(\"cannot overwrite non-directory {1} with directory {0}\")]\n\tNonDirectoryToDirectory(String, String),\n\t#[error(\"target {0}: Not a directory\")]\n\tNotADirectory(String),\n\t#[error(\"target directory {0}: Not a directory\")]\n\tTargetNotADirectory(String),\n\t#[error(\"failed to access {0}: Not a directory\")]\n\tFailedToAccessNotADirectory(String),\n}\n\n#[derive(Debug, Error)]\nenum MvFailure {\n\t#[error(transparent)]","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/mv.rs#L39-L75","documentation":"GNU-compatible `mv` error (`MvError::SameFile`, crates/pi-builtins/src/mv.rs:57), raised from `assert_not_same_file`. The source and target resolve to the same file — via canonicalized paths being equal, hardlink/symlink identity detection, or the source being `.` / ending in `/.` — so moving it onto itself is a no-op that `mv` refuses.","triggerScenarios":"`mv file file`; `mv ../dir/file dir/file` (same file via different relative paths); `mv . subdir` or `mv dir/. other` (source is `.` or ends with `/.`); moving a file onto a hardlink to itself; `mv x dir` where `dir` is a symlink to the directory containing `x`.","commonSituations":"Scripts joining an absolute base with an already-absolute path (e.g. `mv \"$f\" \"$PWD/$f\"`); symlinked directories on PATH-like setups making target and source aliases; copy-paste commands where source and target were left identical; moving directories into themselves detected here before the distinct SelfTargetSubdirectory check.","solutions":["Skip the operation when paths are identical: compare canonical paths (`realpath`) before calling mv.","Use distinct source and target names, e.g. `mv file file.bak` if a copy was intended (mv does not copy — use `cp`).","Resolve symlinked directories so source and target no longer alias the same file.","If the goal was moving into a directory, ensure the target is a different directory than the source's parent."],"exampleFix":"# before\nmv \"$file\" \"$OUT_DIR/$file\"   # OUT_DIR equals the file's dir -> same file\n# after\nsrc_real=$(realpath \"$file\"); dst_real=$(realpath -m \"$OUT_DIR/$(basename \"$file\")\")\n[ \"$src_real\" != \"$dst_real\" ] && mv \"$file\" \"$OUT_DIR/\" || echo \"skipping: same file\"","handlingStrategy":"validation","validationCode":"[ \"$(realpath \"$src\")\" != \"$(realpath -m \"$dst\")\" ] || { echo \"same file, skipping\"; exit 0; }","typeGuard":null,"tryCatchPattern":"if ! mv \"$src\" \"$dst\" 2>err.txt; then grep -q 'are the same file' err.txt && exit 0; cat err.txt >&2; exit 1; fi","preventionTips":["Compare canonicalized (realpath) source and target before moving.","Never use mv to copy — use cp when a same-named copy is the goal.","Beware symlinked directories making two spellings resolve to one file.","Treat `.` and path/`/.` operands as always-invalid mv sources."],"tags":["filesystem","mv","same-file","hardlink"],"backgroundTag":"source-and-target-are-the-same-file","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}