fix: handle dotted names and .lua extension in meta path + name check

Two bugs:

1. Meta stem fallback used raw instance name (unslugged), so names with
   forbidden chars like '/' would create bogus directory components in
   the meta path. Fix: fallback now slugifies + init-prefixes, matching
   name_for_inst.

2. AdjacentMetadata name check used split('.').next() to extract the
   filesystem stem, breaking dotted names like "Name.new" (stem became
   "Name", mismatched the instance name, wrote an unnecessary name
   property). Fix: check the conditions that cause name_for_inst to
   diverge (invalid chars or init-prefix) directly instead of comparing
   path stems.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 17:30:21 +01:00
parent 5b1b5db06c
commit 14bbdaf560
4 changed files with 45 additions and 18 deletions

View File

@@ -166,7 +166,19 @@ pub fn syncback_lua<'sync>(
.and_then(|s| s.strip_suffix(ext.as_str()))
.map(str::to_owned)
})
.unwrap_or_else(|| snapshot.new_inst().name.clone());
.unwrap_or_else(|| {
let name = &snapshot.new_inst().name;
let base = if crate::syncback::validate_file_name(name).is_err() {
crate::syncback::slugify_name(name)
} else {
name.clone()
};
if base.to_lowercase() == "init" {
format!("_{base}")
} else {
base
}
});
fs_snapshot.add_file(
parent_location.join(format!("{meta_stem}.meta.json")),
serde_json::to_vec_pretty(&meta).context("cannot serialize metadata")?,