Add collaborative authored-file safety

This commit is contained in:
Rbanh committed 2026-07-12 11:27:57 -04:00
1 parent b4aa61e394
commit 5a82a9ee29
23 files changed
+2857 -89

No files matched your search

+20 -12
View File
@@ -1570,7 +1570,7 @@ pub fn set_scene_composition_with_history(world: &mut World, new: SceneCompositi
pub fn apply_command_undo(world: &mut World) {
let candidate = world.resource::<EditorHistory>().undo_stack.last().cloned();
if let Some(candidate) = candidate {
if let Err(error) = prepare_prefab_source_history(&candidate, true) {
if let Err(error) = prepare_prefab_source_history(world, &candidate, true) {
world.resource_mut::<EditorHistory>().status = format!("Undo blocked: {error}");
world
.resource_mut::<SceneIo>()
@@ -1591,7 +1591,7 @@ pub fn apply_command_undo(world: &mut World) {
pub fn apply_command_redo(world: &mut World) {
let candidate = world.resource::<EditorHistory>().redo_stack.last().cloned();
if let Some(candidate) = candidate {
if let Err(error) = prepare_prefab_source_history(&candidate, false) {
if let Err(error) = prepare_prefab_source_history(world, &candidate, false) {
world.resource_mut::<EditorHistory>().status = format!("Redo blocked: {error}");
world
.resource_mut::<SceneIo>()
@@ -1609,8 +1609,13 @@ pub fn apply_command_redo(world: &mut World) {
mark_dirty(world);
}
fn prepare_prefab_source_history(command: &EditorCommand, undo: bool) -> Result<(), String> {
fn prepare_prefab_source_history(
world: &mut World,
command: &EditorCommand,
undo: bool,
) -> Result<(), String> {
let EditorCommand::ApplyPrefabToSource {
entity,
source_path,
before_source,
after_source,
@@ -1624,15 +1629,18 @@ fn prepare_prefab_source_history(command: &EditorCommand, undo: bool) -> Result<
} else {
(before_source, after_source)
};
let current = std::fs::read_to_string(source_path)
.map_err(|error| format!("could not read {}: {error}", source_path.display()))?;
if &current != expected {
return Err(format!(
"{} changed outside this history command",
source_path.display()
));
}
crate::scene::recovery::atomic_write(source_path, replacement.as_bytes())
let expected =
crate::collaboration::FileSnapshot::from_loaded_bytes(source_path, expected.as_bytes());
crate::collaboration::publish_authored_file(
world,
source_path,
replacement.as_bytes(),
&expected,
crate::collaboration::FileWriteIntent::PrefabSourceHistory {
instance_root: *entity,
},
)
.map(|_| ())
}
fn undo_command(world: &mut World, command: &mut EditorCommand) {