Explain protected source destination collisions during Save As

This commit is contained in:
2026-10-01 18:13:23 -07:00
parent ea23e22926
commit 0e83157e09
2 changed files with 165 additions and 2 deletions
+22 -2
View File
@@ -5605,6 +5605,7 @@ fn write_snapshot_inner(
.map_err(|errors| crate::document::DocumentError::Source(errors).to_string())?,
);
}
let has_original_destination = previous.is_some();
let previous = previous.filter(|disk| {
path.parent()
.filter(|p| !p.as_os_str().is_empty())
@@ -5615,14 +5616,33 @@ fn write_snapshot_inner(
== Some(&disk.root)
&& entry == disk.bundle.entry
});
// A missing-file expectation colliding with an existing destination is
// not evidence that an observed dependency changed outside the editor.
// Keep save_project's conflict reporting unchanged for that latter case.
let saving_existing = previous.is_some();
let destination_error = |error: source_files::SourceFileError| match error {
source_files::SourceFileError::Conflict(paths) => {
let guidance = if saving_existing {
"Review the new included file's destination before saving."
} else if has_original_destination {
"Choose a fresh directory for Save As, or use Save All to update the open project's current entry."
} else {
"Choose a fresh directory for Save As."
};
format!(
"Source destination files already exist: {paths:?}. Existing files are protected. {guidance}"
)
}
other => other.to_string(),
};
let mut disk = match previous {
Some(disk) => disk,
None => source_files::new_project(&path, LIMITS).map_err(|e| e.to_string())?,
None => source_files::new_project(&path, LIMITS).map_err(&destination_error)?,
};
for path in snapshot.bundle.files.keys() {
if !disk.expectations.contains_key(path) {
source_files::expect_new_file(&mut disk, path, LIMITS)
.map_err(|e| e.to_string())?;
.map_err(&destination_error)?;
}
}
Some(source_files::save_project(&disk, &snapshot, LIMITS).map_err(|e| e.to_string())?)