From 122602df8af000bb73cbb807b98b87b7d7653e74 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 12 Mar 2026 21:04:43 -0500 Subject: [PATCH] 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. --- src/rojo_ref.rs | 20 ++++++++++++-------- src/snapshot/patch_apply.rs | 9 +-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/rojo_ref.rs b/src/rojo_ref.rs index 6783a541..9a1732bd 100644 --- a/src/rojo_ref.rs +++ b/src/rojo_ref.rs @@ -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 = WalkDir::new(root) .follow_links(true) .into_iter() .filter_map(|e: Result| 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(); diff --git a/src/snapshot/patch_apply.rs b/src/snapshot/patch_apply.rs index 9affe7c6..618864b0 100644 --- a/src/snapshot/patch_apply.rs +++ b/src/snapshot/patch_apply.rs @@ -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 { let instance = tree.get_instance(id)?; instance @@ -409,7 +402,7 @@ fn find_meta_or_model_path(tree: &RojoTree, id: Ref) -> Option { .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() }