Refactor metadata name handling for improved clarity

- Updated comments in `json_model.rs` and `meta_file.rs` to clarify the logic for storing the real name of instances when the filesystem name differs due to slugification or deduplication.
- Simplified the conditions under which the real name is preserved, ensuring better readability and understanding of the code's intent.
This commit is contained in:
Joe 2026-02-10 17:34:12 -06:00
parent 5a5e1a0c77
commit f38c1f1311
2 changed files with 14 additions and 12 deletions

View file

@ -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());
}

View file

@ -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