{"record":{"id":"0cc0f30afd2cd4f2","repo":"zed-industries/zed","slug":"target-already-exists","errorCode":null,"errorMessage":"{target:?} already exists","messagePattern":"(.+?) already exists","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/fs/src/fs.rs","lineNumber":806,"sourceCode":"        futures::io::copy(content, &mut file).await?;\n        Ok(())\n    }\n\n    async fn extract_tar_file(\n        &self,\n        path: &Path,\n        content: Archive<Pin<&mut (dyn AsyncRead + Send)>>,\n    ) -> Result<()> {\n        content.unpack(path).await?;\n        Ok(())\n    }\n\n    async fn copy_file(&self, source: &Path, target: &Path, options: CopyOptions) -> Result<()> {\n        if !options.overwrite && smol::fs::metadata(target).await.is_ok() {\n            if options.ignore_if_exists {\n                return Ok(());\n            } else {\n                anyhow::bail!(\"{target:?} already exists\");\n            }\n        }\n\n        smol::fs::copy(source, target).await?;\n        Ok(())\n    }\n\n    async fn rename(&self, source: &Path, target: &Path, options: RenameOptions) -> Result<()> {\n        if options.create_parents {\n            if let Some(parent) = target.parent() {\n                self.create_dir(parent).await?;\n            }\n        }\n\n        if options.overwrite {\n            smol::fs::rename(source, target).await?;\n            return Ok(());\n        }","sourceCodeStart":788,"sourceCodeEnd":824,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/fs/src/fs.rs#L788-L824","documentation":"RealFs::copy_file refuses to overwrite: when the target path already exists (smol::fs::metadata succeeds) and CopyOptions has overwrite=false, it bails with the target path — unless ignore_if_exists=true, which turns the collision into a silent Ok. The check is deliberately TOCTOU-racy upstream of smol::fs::copy; it is a policy guard, not an atomic compare.","triggerScenarios":"fs.copy_file(source, target, CopyOptions { overwrite: false, ignore_if_exists: false, .. }) with an existing file or directory at target.","commonSituations":"Re-running an install/sync step that copies binaries or assets into a populated directory, two tasks writing the same destination, or restoring a backup over existing files.","solutions":["Pass CopyOptions { overwrite: true, .. } when replacing is intended","Pass ignore_if_exists: true to skip existing targets silently","Otherwise remove/rename the target before copying"],"exampleFix":"// before\nfs.copy_file(&source, &target, CopyOptions { overwrite: false, ignore_if_exists: false }).await?; // \"{target:?} already exists\"\n\n// after\nfs.copy_file(&source, &target, CopyOptions { overwrite: true, ignore_if_exists: false }).await?;","handlingStrategy":"validation","validationCode":"if !options.overwrite && smol::fs::metadata(target).await.is_ok() {\n    // decide now: skip, replace, or abort — instead of letting copy_file bail\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = fs.copy_file(&source, &target, options).await {\n    if e.to_string().contains(\"already exists\") { /* skip or overwrite */ } else { return Err(e); }\n}","preventionTips":["Always set overwrite/ignore_if_exists deliberately rather than relying on defaults","For idempotent installers, prefer ignore_if_exists: true"],"tags":["filesystem","copy","file-exists","zed-fs"],"backgroundTag":"file-already-exists","analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}