zed-industries/zed · error

{target_item:?} already exists

Error message

{target_item:?} already exists

What it means

Inside the directory-copy loop (copy with entries), each item is materialized at target/<relative_path>; if that target item exists, overwrite=false, and ignore_if_exists=false, the copy aborts with the offending path. Directories are removed-then-recreated only after this guard passes, so an existing directory is an error, not something the code quietly merges.

Source

Thrown at crates/fs/src/fs.rs:3494

        });

        match result {
            Ok(_) => {
                state.trash.lock().remove(trash_id);
                state.emit_event([(path.clone(), Some(PathEventKind::Created))]);
                Ok(path)
            }
            Err(_) => {
                // For now we'll just assume that this failed because it was a
                // collision error, which I think that, for the time being, is
                // the only case where this could fail?
                Err(TrashRestoreError::Collision { path })
            }
        }
    }

    #[cfg(feature = "test-support")]
    fn as_fake(&self) -> Arc<FakeFs> {
        self.this.upgrade().unwrap()
    }
}

pub async fn copy_recursive<'a>(
    fs: &'a dyn Fs,
    source: &'a Path,
    target: &'a Path,
    options: CopyOptions,
) -> Result<()> {
    for (item, is_dir) in read_dir_items(fs, source).await? {
        let Ok(item_relative_path) = item.strip_prefix(source) else {
            continue;
        };
        let target_item = if item_relative_path == Path::new("") {
            target.to_path_buf()
        } else {
            target.join(item_relative_path)

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Pass overwrite: true in the CopyOptions for the tree copy when replacing is intended
  2. Pass ignore_if_exists: true to skip colliding items and keep the rest
  3. Clear the destination subtree first if a clean copy is required

Example fix

// before
fs.copy(&source_dir, &target_dir, CopyOptions { overwrite: false, ignore_if_exists: false }).await?; // "{target_item:?} already exists"

// after
fs.copy(&source_dir, &target_dir, CopyOptions { overwrite: true, ignore_if_exists: false }).await?;
Defensive patterns

Strategy: validation

Validate before calling

if !options.overwrite && fs.metadata(&target).await.is_ok() {
    // pre-scan destination and decide skip vs replace before the per-item bail
}

Try / catch

if let Err(e) = fs.copy(&source_dir, &target_dir, options).await {
    if e.to_string().contains("already exists") { /* rerun with overwrite:true */ } else { return Err(e); }
}

Prevention

When it happens

Trigger: fs copy of a directory tree (copy_entries/copy with CopyOptions { overwrite: false, ignore_if_exists: false }) where any file or subdirectory already exists at the destination.

Common situations: Re-extracting or re-copying an archive/project into a non-empty destination, installing extensions/themes over a previous version, or concurrent writers producing the same nested path.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20). Data as JSON: /api/errors/4c8bbc61dcd740b1. Report an issue: GitHub.