{"record":{"id":"2037069846e3c98c","repo":"nikivdev/code","slug":"refusing-to-overwrite","errorCode":null,"errorMessage":"Refusing to overwrite {}","messagePattern":"Refusing to overwrite (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/archive.rs","lineNumber":122,"sourceCode":"            .and_then(|name| name.to_str())\n            .map(|name| self.skip_names.contains(&name))\n            .unwrap_or(false)\n    }\n}\n\nfn copy_dir_all(from: &Path, to: &Path, filter: &ArchiveFilter) -> Result<()> {\n    fs::create_dir_all(to).with_context(|| format!(\"failed to create {}\", to.display()))?;\n    for entry in fs::read_dir(from).with_context(|| format!(\"failed to read {}\", from.display()))? {\n        let entry = entry?;\n        let path = entry.path();\n        if filter.should_skip(&path) {\n            continue;\n        }\n        let file_type = entry.file_type()?;\n        let target = to.join(entry.file_name());\n\n        if target.exists() {\n            bail!(\"Refusing to overwrite {}\", target.display());\n        }\n\n        if file_type.is_dir() {\n            copy_dir_all(&path, &target, filter)?;\n        } else if file_type.is_file() {\n            fs::copy(&path, &target)\n                .with_context(|| format!(\"failed to copy {}\", path.display()))?;\n        } else if file_type.is_symlink() {\n            let link_target = fs::read_link(&path)\n                .with_context(|| format!(\"failed to read link {}\", path.display()))?;\n            copy_symlink(&link_target, &target)?;\n        }\n    }\n    Ok(())\n}\n\nfn copy_symlink(target: &Path, dest: &Path) -> Result<()> {\n    #[cfg(unix)]","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/archive.rs#L104-L140","documentation":"Thrown by copy_dir_all in archive.rs when, during the recursive archive copy, a destination path already exists. The tool refuses to clobber existing files/directories rather than silently overwrite user data.","triggerScenarios":"copy_dir_all (recursively, and via run or copy_symlink) encounters target.join(file_name) that already exists in the destination archive directory — e.g. archiving into a directory from a previous run with the same slug.","commonSituations":"Re-running the archive with the same message slug after a partial or completed previous archive; leftover files from an interrupted run; archives that share names across projects in ~/archive/code.","solutions":["Remove or rename the existing archive directory at the target path before re-running","Use a different archive message to get a unique slug","Add logic in the caller to pick a unique destination (timestamped suffix) before copying"],"exampleFix":"// before\narchive --message \"snapshot\"   # snapshot already archived\n// after\narchive --message \"snapshot-2026-09-01\"   # unique slug avoids collision","handlingStrategy":"validation","validationCode":"fn archive_target_free(home: &Path, slug: &str) -> bool {\n    !home.join(\"archive\").join(\"code\").join(slug).exists()\n}\nif !archive_target_free(&home, &slug) {\n    eprintln!(\"archive target already exists; pick a new message\");\n}","typeGuard":null,"tryCatchPattern":"match archive::run(opts) {\n    Err(e) if e.to_string().starts_with(\"Refusing to overwrite\") => {\n        eprintln!(\"{}\\nRemove/rename the existing archive or change the message.\", e);\n        std::process::exit(2);\n    }\n    other => other,\n}","preventionTips":["Use timestamped or unique slugs for repeat archives","Clean up partial archives from interrupted runs before retrying","Check ~/archive/code for name collisions before archiving"],"tags":["filesystem","overwrite-protection","copy","conflict"],"backgroundTag":"file-already-exists","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}