{"record":{"id":"b15ab05e36318c8e","repo":"nikivdev/code","slug":"source-and-destination-are-the-same-path","errorCode":null,"errorMessage":"Source and destination are the same path.","messagePattern":"Source and destination are the same path\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/code.rs","lineNumber":279,"sourceCode":"        cmd.skip_codex,\n    )\n}\n\n/// Migrate a folder to an arbitrary target path (not necessarily ~/code).\nfn migrate_to_path(\n    from: &Path,\n    target: &Path,\n    copy: bool,\n    dry_run: bool,\n    skip_claude: bool,\n    skip_codex: bool,\n) -> Result<()> {\n    let target_display = target.display().to_string();\n    let action = if copy { \"copy\" } else { \"move\" };\n    let action_past = if copy { \"Copied\" } else { \"Moved\" };\n\n    if from == target {\n        bail!(\"Source and destination are the same path.\");\n    }\n    if !from.exists() {\n        bail!(\"Source folder does not exist: {}\", from.display());\n    }\n    if !from.is_dir() {\n        bail!(\"Source path is not a directory: {}\", from.display());\n    }\n    if target.exists() {\n        bail!(\"Destination already exists: {}\", target.display());\n    }\n    if target.starts_with(from) {\n        bail!(\"Destination cannot be inside the source folder.\");\n    }\n\n    // Create parent directories if needed\n    if let Some(parent) = target.parent() {\n        if !parent.exists() {\n            if dry_run {","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/code.rs#L261-L297","documentation":"Thrown by migrate_to_path (src/code.rs:279) when the source and destination paths resolve to the same path. Copying/moving a folder onto itself is a no-op at best and dangerous at worst, so it is rejected up front before the `copy` or `move` action executes.","triggerScenarios":"Running `f migrate <src> <src>` or paths that canonicalize identically (e.g. `f migrate . .`, `f migrate ~/code/x ~/code/../code/x`), including the single-target form where <target> equals the current directory's resolved path.","commonSituations":"Script variables that happen to hold the same value; relative-vs-absolute spellings of the same directory; forgetting you are already cd'd into the source folder.","solutions":["Pass a destination that is a different path: `f migrate ~/code/src ~/code/src-renamed`.","Check the resolved paths (`realpath <from>` vs `realpath <target>`) — they must differ.","If you only wanted to relocate the current dir, run from its parent: `cd .. && f migrate <name> <new-location>`.","Nothing to fix if the move was unintentional duplicate — simply skip the command."],"exampleFix":"// before\n$ f migrate ~/code/myapp ~/code/myapp\nError: Source and destination are the same path.\n// after\n$ f migrate ~/code/myapp ~/dev/myapp","handlingStrategy":"validation","validationCode":"// Shell: compare canonicalized paths before migrating\nFROM=$(realpath -m \"$SRC\"); TO=$(realpath -m \"$DST\")\n[ \"$FROM\" != \"$TO\" ] || { echo \"source and destination are identical\"; exit 1; }","typeGuard":"fn paths_differ(a: &Path, b: &Path) -> bool {\n    match (a.canonicalize(), b.canonicalize()) {\n        (Ok(a), Ok(b)) => a != b,\n        _ => a != b,\n    }\n}","tryCatchPattern":"match run_migrate(opts) {\n    Err(e) if e.to_string().contains(\"same path\") => {\n        eprintln!(\"Source equals destination; nothing to migrate.\");\n    }\n    other => other?,\n}","preventionTips":["Canonicalize both paths (realpath) in scripts before calling migrate","Don't run migrate while cd'd inside the source directory","Compare resolved destinations when source/target come from variables"],"tags":["invalid-argument","cli","rust","path-collision"],"backgroundTag":"identical-source-and-destination","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}