forked from rojo-rbx/rojo
fix: simplify meta stem to instance name + slugify + init-prefix
Drop the strip_suffix(extension) approach for computing adjacent meta file names. Instead, use the instance name directly (slugified if it has invalid filesystem chars, prefixed with '_' if it's "init"). This is the same logic as the original code plus init-prefix handling, and correctly preserves dots in instance names like "Name.new". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -109,27 +109,17 @@ pub fn syncback_csv<'sync>(
|
|||||||
|
|
||||||
if !meta.is_empty() {
|
if !meta.is_empty() {
|
||||||
let parent = snapshot.path.parent_err()?;
|
let parent = snapshot.path.parent_err()?;
|
||||||
let meta_stem = snapshot.middleware
|
let instance_name = &new_inst.name;
|
||||||
.and_then(|mw| {
|
let base = if crate::syncback::validate_file_name(instance_name).is_err() {
|
||||||
let ext = format!(".{}", crate::syncback::extension_for_middleware(mw));
|
crate::syncback::slugify_name(instance_name)
|
||||||
snapshot.path.file_name()
|
} else {
|
||||||
.and_then(|n| n.to_str())
|
instance_name.clone()
|
||||||
.and_then(|s| s.strip_suffix(ext.as_str()))
|
};
|
||||||
.map(str::to_owned)
|
let meta_stem = if base.to_lowercase() == "init" {
|
||||||
})
|
format!("_{base}")
|
||||||
.unwrap_or_else(|| {
|
} else {
|
||||||
let name = &new_inst.name;
|
base
|
||||||
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(
|
fs_snapshot.add_file(
|
||||||
parent.join(format!("{meta_stem}.meta.json")),
|
parent.join(format!("{meta_stem}.meta.json")),
|
||||||
serde_json::to_vec_pretty(&meta).context("cannot serialize metadata")?,
|
serde_json::to_vec_pretty(&meta).context("cannot serialize metadata")?,
|
||||||
|
|||||||
@@ -158,27 +158,17 @@ pub fn syncback_lua<'sync>(
|
|||||||
|
|
||||||
if !meta.is_empty() {
|
if !meta.is_empty() {
|
||||||
let parent_location = snapshot.path.parent_err()?;
|
let parent_location = snapshot.path.parent_err()?;
|
||||||
let meta_stem = snapshot.middleware
|
let instance_name = &snapshot.new_inst().name;
|
||||||
.and_then(|mw| {
|
let base = if crate::syncback::validate_file_name(instance_name).is_err() {
|
||||||
let ext = format!(".{}", crate::syncback::extension_for_middleware(mw));
|
crate::syncback::slugify_name(instance_name)
|
||||||
snapshot.path.file_name()
|
} else {
|
||||||
.and_then(|n| n.to_str())
|
instance_name.clone()
|
||||||
.and_then(|s| s.strip_suffix(ext.as_str()))
|
};
|
||||||
.map(str::to_owned)
|
let meta_stem = if base.to_lowercase() == "init" {
|
||||||
})
|
format!("_{base}")
|
||||||
.unwrap_or_else(|| {
|
} else {
|
||||||
let name = &snapshot.new_inst().name;
|
base
|
||||||
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(
|
fs_snapshot.add_file(
|
||||||
parent_location.join(format!("{meta_stem}.meta.json")),
|
parent_location.join(format!("{meta_stem}.meta.json")),
|
||||||
serde_json::to_vec_pretty(&meta).context("cannot serialize metadata")?,
|
serde_json::to_vec_pretty(&meta).context("cannot serialize metadata")?,
|
||||||
|
|||||||
@@ -58,27 +58,17 @@ pub fn syncback_txt<'sync>(
|
|||||||
|
|
||||||
if !meta.is_empty() {
|
if !meta.is_empty() {
|
||||||
let parent = snapshot.path.parent_err()?;
|
let parent = snapshot.path.parent_err()?;
|
||||||
let meta_stem = snapshot.middleware
|
let instance_name = &new_inst.name;
|
||||||
.and_then(|mw| {
|
let base = if crate::syncback::validate_file_name(instance_name).is_err() {
|
||||||
let ext = format!(".{}", crate::syncback::extension_for_middleware(mw));
|
crate::syncback::slugify_name(instance_name)
|
||||||
snapshot.path.file_name()
|
} else {
|
||||||
.and_then(|n| n.to_str())
|
instance_name.clone()
|
||||||
.and_then(|s| s.strip_suffix(ext.as_str()))
|
};
|
||||||
.map(str::to_owned)
|
let meta_stem = if base.to_lowercase() == "init" {
|
||||||
})
|
format!("_{base}")
|
||||||
.unwrap_or_else(|| {
|
} else {
|
||||||
let name = &new_inst.name;
|
base
|
||||||
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(
|
fs_snapshot.add_file(
|
||||||
parent.join(format!("{meta_stem}.meta.json")),
|
parent.join(format!("{meta_stem}.meta.json")),
|
||||||
serde_json::to_vec_pretty(&meta).context("could not serialize metadata")?,
|
serde_json::to_vec_pretty(&meta).context("could not serialize metadata")?,
|
||||||
|
|||||||
Reference in New Issue
Block a user