Add support for filtering hidden services in syncback

- Introduced a new configuration option `ignore_hidden_services` in `SyncbackRules` to allow filtering of internal services during syncback.
- Added a constant `VISIBLE_SERVICES` to define which services are considered visible and should be included when the filtering option is enabled.
- Implemented the `strip_hidden_services` function to remove non-visible services from the syncback process.
- Updated the syncback loop to apply the filtering logic based on the new configuration option.
- Enhanced path uniqueness checks by pre-computing duplicate sibling information for improved performance in the syncback process.
This commit is contained in:
Joe 2026-01-30 10:15:21 -06:00
parent 5a85c5145c
commit 9b412d28ae
3 changed files with 220 additions and 63 deletions

View file

@ -44,6 +44,26 @@ pub use snapshot::{inst_path, SyncbackData, SyncbackSnapshot};
/// new files.
const DEBUG_MODEL_FORMAT_VAR: &str = "ROJO_SYNCBACK_DEBUG";
/// Services that are considered "visible" and will be included when
/// `ignoreHiddenServices` is enabled. All other services will be ignored.
const VISIBLE_SERVICES: &[&str] = &[
"Lighting",
"MaterialService",
"NetworkClient",
"ReplicatedFirst",
"ReplicatedStorage",
"ServerScriptService",
"ServerStorage",
"SoundService",
"StarterGui",
"StarterPack",
"StarterPlayer",
"Teams",
"TextChatService",
"VoiceChatService",
"Workspace",
];
/// A glob that can be used to tell if a path contains a `.git` folder.
static GIT_IGNORE_GLOB: OnceLock<Glob> = OnceLock::new();
@ -91,6 +111,17 @@ pub fn syncback_loop(
strip_unknown_root_children(&mut new_tree, old_tree);
}
// If ignoreHiddenServices is enabled, filter to only visible services
if project
.syncback_rules
.as_ref()
.map(|rules| rules.ignore_hidden_services())
.unwrap_or(false)
{
log::debug!("Filtering hidden services");
strip_hidden_services(&mut new_tree);
}
log::debug!("Collecting referents for new DOM...");
let deferred_referents = collect_referents(&new_tree, &pre_prune_paths);
@ -408,6 +439,12 @@ pub struct SyncbackRules {
/// Defaults to `false`.
#[serde(skip_serializing_if = "Option::is_none")]
encode_windows_invalid_chars: Option<bool>,
/// When enabled, only "visible" services will be synced back. This includes
/// commonly used services like Workspace, ReplicatedStorage, ServerScriptService,
/// etc., while ignoring internal/hidden services like Chat, HttpService, etc.
/// Defaults to `false`.
#[serde(skip_serializing_if = "Option::is_none")]
ignore_hidden_services: Option<bool>,
}
impl SyncbackRules {
@ -453,6 +490,14 @@ impl SyncbackRules {
pub fn encode_windows_invalid_chars(&self) -> bool {
self.encode_windows_invalid_chars.unwrap_or(true)
}
/// Returns whether hidden/internal services should be ignored during
/// syncback. When `true`, only visible services like Workspace,
/// ReplicatedStorage, etc. will be synced. Defaults to `false`.
#[inline]
pub fn ignore_hidden_services(&self) -> bool {
self.ignore_hidden_services.unwrap_or(false)
}
}
fn is_valid_path(globs: &Option<Vec<Glob>>, base_path: &Path, path: &Path) -> bool {
@ -524,6 +569,29 @@ fn descendants(dom: &WeakDom, root_ref: Ref) -> Vec<Ref> {
ordered
}
/// Removes root children (services) that are not in the `VISIBLE_SERVICES` list.
/// This is used when `ignoreHiddenServices` is enabled to filter out internal
/// services like Chat, HttpService, etc.
fn strip_hidden_services(dom: &mut WeakDom) {
let root_children = dom.root().children().to_vec();
for child_ref in root_children {
let child = dom
.get_by_ref(child_ref)
.expect("all children of the root should exist in the DOM");
// Check if this service is in the visible services list
if !VISIBLE_SERVICES.contains(&child.name.as_str()) {
log::trace!(
"Pruning hidden service {} of class {}",
child.name,
child.class
);
dom.destroy(child_ref);
}
}
}
/// Removes the children of `new`'s root that are not also children of `old`'s
/// root.
///