diff --git a/src/snapshot_middleware/json_model.rs b/src/snapshot_middleware/json_model.rs index 8b2284fd..064d1ff6 100644 --- a/src/snapshot_middleware/json_model.rs +++ b/src/snapshot_middleware/json_model.rs @@ -77,10 +77,12 @@ pub fn syncback_json_model<'sync>( // could have a performance cost. model.schema = old_inst.metadata().schema.clone(); model.name = old_inst.metadata().specified_name.clone(); - } else if snapshot.needs_meta_name { - // New instance whose filesystem name differs from the instance name - // (due to slugification or deduplication). Store the real name so it - // survives a round-trip through the filesystem. + } + // Filesystem name differs from the instance name (due to slugification + // or deduplication). Store the real name so it survives a round-trip. + // Checked independently: old_inst may exist but lack a specified_name + // (e.g., a previously filesystem-safe name was renamed to need slugification). + if model.name.is_none() && snapshot.needs_meta_name { model.name = Some(snapshot.new_inst().name.clone()); } diff --git a/src/snapshot_middleware/meta_file.rs b/src/snapshot_middleware/meta_file.rs index e23138e0..e9f17708 100644 --- a/src/snapshot_middleware/meta_file.rs +++ b/src/snapshot_middleware/meta_file.rs @@ -162,10 +162,10 @@ impl AdjacentMetadata { .old_inst() .and_then(|inst| inst.metadata().specified_name.clone()) .or_else(|| { - // If this is a new instance and its filesystem name differs from - // the instance name (due to slugification or deduplication), we - // need to specify the name in meta.json so it can be preserved. - if snapshot.old_inst().is_none() && snapshot.needs_meta_name { + // Filesystem name differs from the instance name (due to + // slugification or deduplication). Store the real name so + // it survives a round-trip through the filesystem. + if snapshot.needs_meta_name { Some(snapshot.new_inst().name.clone()) } else { None @@ -424,10 +424,10 @@ impl DirectoryMetadata { .old_inst() .and_then(|inst| inst.metadata().specified_name.clone()) .or_else(|| { - // If this is a new instance and its filesystem name differs from - // the instance name (due to slugification or deduplication), we - // need to specify the name in meta.json so it can be preserved. - if snapshot.old_inst().is_none() && snapshot.needs_meta_name { + // Filesystem name differs from the instance name (due to + // slugification or deduplication). Store the real name so + // it survives a round-trip through the filesystem. + if snapshot.needs_meta_name { Some(snapshot.new_inst().name.clone()) } else { None