mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-22 21:41:37 +00:00
refactor: deduplicate is_meta_or_model into shared helper
Bugbot flagged identical copies in patch_apply.rs and rojo_ref.rs. Extracted to pub(crate) is_meta_or_model_name() in rojo_ref.rs.
This commit is contained in:
parent
3c87b408cc
commit
122602df8a
2 changed files with 13 additions and 16 deletions
|
|
@ -12,6 +12,14 @@ use rbx_dom_weak::{
|
|||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Returns `true` if the filename is a meta or model JSON file.
|
||||
pub(crate) fn is_meta_or_model_name(name: &str) -> bool {
|
||||
name.ends_with(".meta.json5")
|
||||
|| name.ends_with(".model.json5")
|
||||
|| name.ends_with(".meta.json")
|
||||
|| name.ends_with(".model.json")
|
||||
}
|
||||
|
||||
/// Legacy: ID attribute on target instances (kept for backwards compatibility)
|
||||
pub const REF_ID_ATTRIBUTE_NAME: &str = "Rojo_Id";
|
||||
/// Legacy: Pointer attribute prefix using IDs (kept for backwards compatibility)
|
||||
|
|
@ -389,19 +397,15 @@ impl RefPathIndex {
|
|||
use rayon::prelude::*;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
fn is_meta_or_model(name: &str) -> bool {
|
||||
name.ends_with(".meta.json5")
|
||||
|| name.ends_with(".model.json5")
|
||||
|| name.ends_with(".meta.json")
|
||||
|| name.ends_with(".model.json")
|
||||
}
|
||||
|
||||
let meta_paths: Vec<std::path::PathBuf> = WalkDir::new(root)
|
||||
.follow_links(true)
|
||||
.into_iter()
|
||||
.filter_map(|e: Result<walkdir::DirEntry, _>| e.ok())
|
||||
.filter(|e: &walkdir::DirEntry| {
|
||||
e.file_type().is_file() && e.file_name().to_str().is_some_and(is_meta_or_model)
|
||||
e.file_type().is_file()
|
||||
&& e.file_name()
|
||||
.to_str()
|
||||
.is_some_and(is_meta_or_model_name)
|
||||
})
|
||||
.map(|e: walkdir::DirEntry| e.into_path())
|
||||
.collect();
|
||||
|
|
|
|||
|
|
@ -393,13 +393,6 @@ fn apply_update_child(context: &mut PatchApplyContext, tree: &mut RojoTree, patc
|
|||
context.applied_patch_set.updated.push(applied_patch)
|
||||
}
|
||||
|
||||
fn is_meta_or_model(name: &str) -> bool {
|
||||
name.ends_with(".meta.json5")
|
||||
|| name.ends_with(".model.json5")
|
||||
|| name.ends_with(".meta.json")
|
||||
|| name.ends_with(".model.json")
|
||||
}
|
||||
|
||||
fn find_meta_or_model_path(tree: &RojoTree, id: Ref) -> Option<PathBuf> {
|
||||
let instance = tree.get_instance(id)?;
|
||||
instance
|
||||
|
|
@ -409,7 +402,7 @@ fn find_meta_or_model_path(tree: &RojoTree, id: Ref) -> Option<PathBuf> {
|
|||
.find(|p| {
|
||||
p.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.is_some_and(is_meta_or_model)
|
||||
.is_some_and(crate::is_meta_or_model_name)
|
||||
})
|
||||
.cloned()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue