Update vscode-rojo submodule reference and complete migration plan for path encoding

- Updated the vscode-rojo submodule to the latest commit.
- Marked all phases of the path encoding migration plan as completed, transitioning to a slugify and deduplication approach.
- Updated documentation to reflect changes in filename handling and metadata management.
This commit is contained in:
Joe 2026-02-10 03:14:18 -06:00
parent 0955e38b45
commit 126c8e66a4
77 changed files with 3512 additions and 799 deletions

View file

@ -11,11 +11,11 @@ use std::{
use crate::{
message_queue::MessageQueue,
path_encoding::encode_path_name,
snapshot::{
apply_patch_set, compute_patch_set, AppliedPatchSet, InstigatingSource, PatchSet, RojoTree,
},
snapshot_middleware::{snapshot_from_vfs, snapshot_project_node},
syncback::{name_needs_slugify, slugify_name},
};
/// Processes file change events, updates the DOM, and sends those updates
@ -226,6 +226,42 @@ impl JobThreadContext {
}
}
/// Upsert the `name` field in a `.meta.json5` file. If the file exists,
/// parse it and add/update the `name` key. If it doesn't exist, create it
/// with just the `name` key.
fn upsert_meta_name_field(&self, meta_path: &Path, real_name: &str) {
self.suppress_path(meta_path);
let mut obj = if meta_path.exists() {
match fs::read(meta_path) {
Ok(bytes) => match crate::json::from_slice::<serde_json::Value>(&bytes) {
Ok(serde_json::Value::Object(map)) => map,
_ => serde_json::Map::new(),
},
Err(_) => serde_json::Map::new(),
}
} else {
serde_json::Map::new()
};
obj.insert(
"name".to_string(),
serde_json::Value::String(real_name.to_string()),
);
match crate::json::to_vec_pretty_sorted(&serde_json::Value::Object(obj)) {
Ok(content) => {
if let Err(err) = fs::write(meta_path, &content) {
log::error!(
"Failed to write name to meta file {}: {}",
meta_path.display(),
err
);
}
}
Err(err) => {
log::error!("Failed to serialize meta for name field: {}", err);
}
}
}
/// Computes and applies patches to the DOM for a given file path.
///
/// This function finds the nearest ancestor to the given path that has associated instances
@ -561,47 +597,27 @@ impl JobThreadContext {
let applied_patch = {
let mut tree = self.tree.lock().unwrap();
// NOTE: We do NOT delete files from disk here. The API handler
// (handle_api_write → syncback_removed_instance) already deleted
// the files before sending this PatchSet. Re-deleting would
// destroy any new file created at the same path — e.g., when an
// instance is renamed from "joe_test" to "joe/test", the new slug
// is also "joe_test", so the API creates a new file at the same
// path that the removal just deleted. If we deleted again here,
// the new file would be destroyed.
//
// The PatchSet removal only needs to update the DOM tree (handled
// by apply_patch_set below).
for &id in &patch_set.removed_instances {
if let Some(instance) = tree.get_instance(id) {
if let Some(instigating_source) = &instance.metadata().instigating_source {
match instigating_source {
InstigatingSource::Path(path) => {
// Guard: file may already be deleted by the API's
// syncback_removed_instance before this PatchSet arrives.
if path.exists() {
if path.is_dir() {
log::info!(
"Two-way sync: Removing directory {}",
path.display()
);
if let Err(err) = fs::remove_dir_all(path) {
log::error!(
"Failed to remove directory {:?} for instance {:?}: {}",
path,
id,
err
);
}
} else {
log::info!(
"Two-way sync: Removing file {}",
path.display()
);
if let Err(err) = fs::remove_file(path) {
log::error!(
"Failed to remove file {:?} for instance {:?}: {}",
path,
id,
err
);
}
}
} else {
log::info!(
"Two-way sync: File already removed: {}",
path.display()
);
}
log::info!(
"Two-way sync: Removing instance {:?} from tree (path: {})",
id,
path.display()
);
}
InstigatingSource::ProjectNode { .. } => {
log::warn!(
@ -653,17 +669,19 @@ impl JobThreadContext {
if is_init_file {
let dir_path = path.parent().unwrap();
if let Some(grandparent) = dir_path.parent() {
// Use the encoded dir name from the filesystem
// for the old meta lookup, and encode the new
// name for the new path. Using instance.name()
// (decoded) would fail for encoded names.
let dir_name = dir_path
.file_name()
.and_then(|f| f.to_str())
.unwrap_or("");
let encoded_new_name = encode_path_name(new_name);
// Slugify the new name for filesystem safety
let slugified_new_name =
if name_needs_slugify(new_name) {
slugify_name(new_name)
} else {
new_name.to_string()
};
let new_dir_path =
grandparent.join(&encoded_new_name);
grandparent.join(&slugified_new_name);
if new_dir_path != dir_path {
log::info!(
@ -696,7 +714,7 @@ impl JobThreadContext {
let new_meta =
grandparent.join(format!(
"{}.meta.json5",
encoded_new_name
slugified_new_name
));
self.suppress_path_any(&old_meta);
self.suppress_path(&new_meta);
@ -707,14 +725,22 @@ impl JobThreadContext {
self.unsuppress_path(&new_meta);
}
}
// Write name to init.meta.json5 if slug differs
if slugified_new_name != *new_name {
let init_meta = new_dir_path
.join("init.meta.json5");
self.upsert_meta_name_field(
&init_meta, new_name,
);
}
}
}
}
} else if let Some(parent) = path.parent() {
// Derive the suffix from the existing filename
// rather than using replacen with the decoded
// instance name, which fails for encoded names
// (e.g., What%QUESTION%.server.luau).
// rather than using replacen with the instance
// name, which may differ from the filesystem
// name (e.g., slugified names).
let extension = path
.extension()
.and_then(|e| e.to_str())
@ -738,13 +764,18 @@ impl JobThreadContext {
&stem[..stem.len() - script_suffix.len()]
};
let encoded_new_name = encode_path_name(new_name);
let slugified_new_name = if name_needs_slugify(new_name)
{
slugify_name(new_name)
} else {
new_name.to_string()
};
let new_file_name = if extension.is_empty() {
format!("{}{}", encoded_new_name, script_suffix)
format!("{}{}", slugified_new_name, script_suffix)
} else {
format!(
"{}{}.{}",
encoded_new_name, script_suffix, extension
slugified_new_name, script_suffix, extension
)
};
let new_path = parent.join(&new_file_name);
@ -770,11 +801,11 @@ impl JobThreadContext {
overridden_source_path = Some(new_path.clone());
let old_meta = parent
.join(format!("{}.meta.json5", old_base));
let new_meta = parent.join(format!(
"{}.meta.json5",
slugified_new_name
));
if old_meta.exists() {
let new_meta = parent.join(format!(
"{}.meta.json5",
encoded_new_name
));
self.suppress_path_any(&old_meta);
self.suppress_path(&new_meta);
if fs::rename(&old_meta, &new_meta).is_err()
@ -783,6 +814,12 @@ impl JobThreadContext {
self.unsuppress_path(&new_meta);
}
}
// Write name to adjacent meta if slug differs
if slugified_new_name != *new_name {
self.upsert_meta_name_field(
&new_meta, new_name,
);
}
}
}
}
@ -861,10 +898,9 @@ impl JobThreadContext {
format!("init{}.luau", new_suffix)
}
} else {
// Derive the encoded base name from the
// filesystem path, not instance.name()
// (which is decoded). This preserves
// encoding like What%QUESTION% on disk.
// Derive the base name from the filesystem
// path, not instance.name() (which may
// differ from the slugified filename).
let stem = actual_file
.file_stem()
.and_then(|s| s.to_str())

View file

@ -13,7 +13,6 @@ mod json;
mod lua_ast;
mod message_queue;
mod multimap;
pub mod path_encoding;
mod path_serializer;
mod project;
mod resolution;

View file

@ -1,342 +0,0 @@
//! Encoding and decoding utilities for special filename characters.
//!
//! This module encodes characters that are problematic in file names:
//! - Windows-invalid characters: < > : " / \ | ? *
//! - Periods (.) to prevent conflicts with file extension parsing
//! - Leading/trailing spaces
//! - Literal percent signs (%) to allow round-tripping
//!
//! Characters are encoded using a %NAME% format (e.g., `<` becomes `%LT%`,
//! `.` becomes `%DOT%`). Literal `%` is escaped as `%%` (like printf).
use std::collections::HashMap;
use std::sync::OnceLock;
/// Mapping of special characters to their encoded representations.
const CHAR_ENCODINGS: &[(&str, &str)] = &[
(".", "%DOT%"),
("<", "%LT%"),
(">", "%GT%"),
(":", "%COLON%"),
("\"", "%QUOTE%"),
("/", "%SLASH%"),
("\\", "%BACKSLASH%"),
("|", "%PIPE%"),
("?", "%QUESTION%"),
("*", "%STAR%"),
];
/// Returns a map from encoded pattern (e.g., "DOT") to decoded char (e.g., ".").
fn get_decode_map() -> &'static HashMap<&'static str, &'static str> {
static DECODE_MAP: OnceLock<HashMap<&'static str, &'static str>> = OnceLock::new();
DECODE_MAP.get_or_init(|| {
let mut map = HashMap::new();
for (char, encoded) in CHAR_ENCODINGS {
// Strip the leading and trailing % from the pattern
let pattern = &encoded[1..encoded.len() - 1];
map.insert(pattern, *char);
}
map
})
}
const SPACE_ENCODING: &str = "%SPACE%";
/// Encodes special characters in a file name.
///
/// This replaces characters like `.`, `<`, `>`, `:`, `"`, `/`, `\`, `|`, `?`, `*`
/// with their encoded representations like `%DOT%`, `%LT%`, `%GT%`, etc.
/// Literal `%` is escaped as `%%`. Leading and trailing spaces are encoded as `%SPACE%`.
pub fn encode_path_name(name: &str) -> String {
let trimmed = name.trim_matches(' ');
// Handle the case where the string is entirely spaces (or empty)
if trimmed.is_empty() {
return SPACE_ENCODING.repeat(name.len());
}
// Count leading and trailing spaces
let leading_spaces = name.len() - name.trim_start_matches(' ').len();
let trailing_spaces = name.len() - name.trim_end_matches(' ').len();
// Get the middle part (without leading/trailing spaces)
let middle = &name[leading_spaces..name.len() - trailing_spaces];
// First: escape % as %% (before adding new % signs from encodings)
let mut encoded_middle = middle.replace('%', "%%");
// Then: encode special characters
for (char, encoded) in CHAR_ENCODINGS {
encoded_middle = encoded_middle.replace(char, encoded);
}
// Build final result with encoded spaces
let encoded_prefix = SPACE_ENCODING.repeat(leading_spaces);
let encoded_suffix = SPACE_ENCODING.repeat(trailing_spaces);
format!("{}{}{}", encoded_prefix, encoded_middle, encoded_suffix)
}
/// Decodes encoded special characters back to their original form.
///
/// This replaces encoded representations like `%DOT%`, `%LT%`, `%GT%`, etc.
/// back to their original characters `.`, `<`, `>`, etc.
/// `%%` is decoded to literal `%`. `%SPACE%` at the start/end is decoded back to spaces.
///
/// Uses a proper left-to-right parser to correctly handle `%%` escaping.
pub fn decode_path_name(name: &str) -> String {
let mut result = name.to_string();
// Count and strip leading %SPACE%
let mut leading_spaces = 0;
while result.starts_with(SPACE_ENCODING) {
leading_spaces += 1;
result = result[SPACE_ENCODING.len()..].to_string();
}
// Count and strip trailing %SPACE%
let mut trailing_spaces = 0;
while result.ends_with(SPACE_ENCODING) {
trailing_spaces += 1;
result = result[..result.len() - SPACE_ENCODING.len()].to_string();
}
// Parse and decode the middle part
let decoded_middle = decode_patterns(&result);
// Rebuild with actual spaces
let prefix = " ".repeat(leading_spaces);
let suffix = " ".repeat(trailing_spaces);
format!("{}{}{}", prefix, decoded_middle, suffix)
}
/// Parses an encoded string left-to-right, properly handling `%%` escapes and `%NAME%` patterns.
fn decode_patterns(input: &str) -> String {
let decode_map = get_decode_map();
let chars: Vec<char> = input.chars().collect();
let mut output = String::with_capacity(input.len());
let mut i = 0;
while i < chars.len() {
if chars[i] == '%' {
// Check for %% (escaped percent)
if i + 1 < chars.len() && chars[i + 1] == '%' {
output.push('%');
i += 2;
continue;
}
// Try to match a %NAME% pattern
if let Some((decoded, consumed)) = try_decode_pattern(&chars, i, decode_map) {
output.push_str(&decoded);
i += consumed;
continue;
}
}
// Regular character, just copy it
output.push(chars[i]);
i += 1;
}
output
}
/// Tries to decode a %NAME% pattern starting at position `start`.
/// Returns Some((decoded_string, chars_consumed)) if successful, None otherwise.
fn try_decode_pattern(
chars: &[char],
start: usize,
decode_map: &HashMap<&str, &str>,
) -> Option<(String, usize)> {
// Must start with %
if chars.get(start) != Some(&'%') {
return None;
}
// Find the closing %
let mut end = start + 1;
while end < chars.len() && chars[end] != '%' {
// Pattern names are uppercase letters only
if !chars[end].is_ascii_uppercase() {
return None;
}
end += 1;
}
// Must have found a closing %
if end >= chars.len() || chars[end] != '%' {
return None;
}
// Extract the pattern name (without the % delimiters)
let pattern_name: String = chars[start + 1..end].iter().collect();
// Look up the pattern
if let Some(&decoded) = decode_map.get(pattern_name.as_str()) {
Some((decoded.to_string(), end - start + 1))
} else {
None
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_encode_all_chars() {
let input = r#".<>:"/\|?*"#;
let expected = "%DOT%%LT%%GT%%COLON%%QUOTE%%SLASH%%BACKSLASH%%PIPE%%QUESTION%%STAR%";
assert_eq!(encode_path_name(input), expected);
}
#[test]
fn test_decode_all_chars() {
let input = "%DOT%%LT%%GT%%COLON%%QUOTE%%SLASH%%BACKSLASH%%PIPE%%QUESTION%%STAR%";
let expected = r#".<>:"/\|?*"#;
assert_eq!(decode_path_name(input), expected);
}
#[test]
fn test_roundtrip() {
let original = "Test<File>With:Special\"Chars/And\\More|Stuff?Here*End";
let encoded = encode_path_name(original);
let decoded = decode_path_name(&encoded);
assert_eq!(decoded, original);
}
#[test]
fn test_no_special_chars() {
let input = "NormalFileName";
assert_eq!(encode_path_name(input), input);
assert_eq!(decode_path_name(input), input);
}
#[test]
fn test_leading_spaces() {
let input = " LeadingSpaces";
let encoded = encode_path_name(input);
assert_eq!(encoded, "%SPACE%%SPACE%LeadingSpaces");
assert_eq!(decode_path_name(&encoded), input);
}
#[test]
fn test_trailing_spaces() {
let input = "TrailingSpaces ";
let encoded = encode_path_name(input);
assert_eq!(encoded, "TrailingSpaces%SPACE%%SPACE%");
assert_eq!(decode_path_name(&encoded), input);
}
#[test]
fn test_both_spaces() {
let input = " Both Spaces ";
let encoded = encode_path_name(input);
assert_eq!(encoded, "%SPACE%Both Spaces%SPACE%");
assert_eq!(decode_path_name(&encoded), input);
}
#[test]
fn test_middle_spaces_unchanged() {
let input = "Middle Spaces Here";
let encoded = encode_path_name(input);
assert_eq!(encoded, "Middle Spaces Here");
assert_eq!(decode_path_name(&encoded), input);
}
#[test]
fn test_roundtrip_with_spaces() {
let original = " <Test> ";
let encoded = encode_path_name(original);
let decoded = decode_path_name(&encoded);
assert_eq!(decoded, original);
}
#[test]
fn test_encode_period() {
let input = "My.Script";
let expected = "My%DOT%Script";
assert_eq!(encode_path_name(input), expected);
}
#[test]
fn test_decode_period() {
let input = "My%DOT%Script";
let expected = "My.Script";
assert_eq!(decode_path_name(input), expected);
}
#[test]
fn test_roundtrip_with_period() {
let original = "My.Module.Name";
let encoded = encode_path_name(original);
let decoded = decode_path_name(&encoded);
assert_eq!(decoded, original);
}
#[test]
fn test_encode_percent() {
let input = "My%Thing";
let expected = "My%%Thing";
assert_eq!(encode_path_name(input), expected);
}
#[test]
fn test_decode_percent() {
let input = "My%%Thing";
let expected = "My%Thing";
assert_eq!(decode_path_name(input), expected);
}
#[test]
fn test_roundtrip_with_percent() {
let original = "My%Thing";
let encoded = encode_path_name(original);
let decoded = decode_path_name(&encoded);
assert_eq!(decoded, original);
}
#[test]
fn test_percent_encoding_pattern_roundtrip() {
// This tests that a name containing what looks like an encoding pattern
// round-trips correctly and doesn't get incorrectly decoded
let original = "My%DOT%Thing";
let encoded = encode_path_name(original);
assert_eq!(encoded, "My%%DOT%%Thing");
let decoded = decode_path_name(&encoded);
assert_eq!(decoded, original);
}
#[test]
fn test_combined_period_and_percent() {
let original = "My.%Thing.Other";
let encoded = encode_path_name(original);
let decoded = decode_path_name(&encoded);
assert_eq!(decoded, original);
}
#[test]
fn test_single_space() {
let input = " ";
let encoded = encode_path_name(input);
assert_eq!(encoded, "%SPACE%");
assert_eq!(decode_path_name(&encoded), input);
}
#[test]
fn test_multiple_spaces_only() {
let input = " ";
let encoded = encode_path_name(input);
assert_eq!(encoded, "%SPACE%%SPACE%%SPACE%");
assert_eq!(decode_path_name(&encoded), input);
}
#[test]
fn test_empty_string() {
let input = "";
let encoded = encode_path_name(input);
assert_eq!(encoded, "");
assert_eq!(decode_path_name(&encoded), input);
}
}

View file

@ -114,14 +114,7 @@ impl ServeSession {
let root_id = tree.get_root_id();
let decode_windows_invalid_chars = root_project
.syncback_rules
.as_ref()
.map(|rules| rules.encode_windows_invalid_chars())
.unwrap_or(true);
let mut instance_context = InstanceContext::new();
instance_context.set_decode_windows_invalid_chars(decode_windows_invalid_chars);
let instance_context = InstanceContext::new();
log::trace!("Generating snapshot of instances from VFS");
let snapshot = snapshot_from_vfs(&instance_context, &vfs, start_path)?;

View file

@ -66,6 +66,12 @@ pub struct InstanceMetadata {
/// A schema provided via a JSON file, if one exists. Will be `None` for
/// all non-JSON middleware.
pub schema: Option<String>,
/// A custom name specified via meta.json or model.json files. If present,
/// this name will be used for the instance while the filesystem name will
/// be slugified to remove illegal characters.
#[serde(skip_serializing_if = "Option::is_none")]
pub specified_name: Option<String>,
}
impl InstanceMetadata {
@ -78,6 +84,7 @@ impl InstanceMetadata {
specified_id: None,
middleware: None,
schema: None,
specified_name: None,
}
}
@ -126,6 +133,13 @@ impl InstanceMetadata {
pub fn schema(self, schema: Option<String>) -> Self {
Self { schema, ..self }
}
pub fn specified_name(self, specified_name: Option<String>) -> Self {
Self {
specified_name,
..self
}
}
}
impl Default for InstanceMetadata {
@ -140,16 +154,6 @@ pub struct InstanceContext {
pub path_ignore_rules: Arc<Vec<PathIgnoreRule>>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub sync_rules: Vec<SyncRule>,
/// Whether to decode special characters in file names.
/// Characters like `%DOT%`, `%LT%`, `%GT%`, `%COLON%`, etc. will be decoded
/// back to `.`, `<`, `>`, `:`, etc. in instance names sent to the plugin.
/// Defaults to true.
#[serde(default = "decode_windows_invalid_chars_default")]
pub decode_windows_invalid_chars: bool,
}
fn decode_windows_invalid_chars_default() -> bool {
true
}
impl InstanceContext {
@ -157,14 +161,9 @@ impl InstanceContext {
Self {
path_ignore_rules: Arc::new(Vec::new()),
sync_rules: Vec::new(),
decode_windows_invalid_chars: true,
}
}
pub fn set_decode_windows_invalid_chars(&mut self, decode: bool) {
self.decode_windows_invalid_chars = decode;
}
/// Extend the list of ignore rules in the context with the given new rules.
pub fn add_path_ignore_rules<I>(&mut self, new_rules: I)
where

View file

@ -11,8 +11,7 @@ properties:
metadata:
ignore_unknown_instances: false
relevant_paths: []
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ properties: {}
metadata:
ignore_unknown_instances: false
relevant_paths: []
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -11,8 +11,7 @@ properties:
metadata:
ignore_unknown_instances: false
relevant_paths: []
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ properties: {}
metadata:
ignore_unknown_instances: false
relevant_paths: []
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ added_instances:
metadata:
ignore_unknown_instances: false
relevant_paths: []
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,9 +10,8 @@ use rbx_dom_weak::{types::Variant, ustr};
use serde::{Deserialize, Serialize};
use crate::{
path_encoding::encode_path_name,
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
syncback::{FsSnapshot, SyncbackReturn, SyncbackSnapshot},
syncback::{name_needs_slugify, slugify_name, FsSnapshot, SyncbackReturn, SyncbackSnapshot},
};
use super::{
@ -110,10 +109,11 @@ pub fn syncback_csv<'sync>(
if !meta.is_empty() {
let parent = snapshot.path.parent_err()?;
let meta_name = if snapshot.encode_windows_invalid_chars() {
encode_path_name(&new_inst.name)
let instance_name = &new_inst.name;
let meta_name = if name_needs_slugify(instance_name) {
slugify_name(instance_name)
} else {
new_inst.name.clone()
instance_name.clone()
};
fs_snapshot.add_file(
parent.join(format!("{}.meta.json5", meta_name)),

View file

@ -138,6 +138,25 @@ pub fn syncback_dir_no_meta<'sync>(
let mut children = Vec::new();
let mut removed_children = Vec::new();
// Seed taken_names with existing files on disk so new children don't
// collide with files already present in the directory.
let mut taken_names: HashSet<String> = snapshot
.vfs()
.read_dir(&snapshot.path)
.ok()
.map(|entries| {
entries
.filter_map(|e| e.ok())
.filter_map(|e| {
e.path()
.file_name()
.and_then(|n| n.to_str())
.map(|n| n.to_lowercase())
})
.collect()
})
.unwrap_or_default();
// Detect duplicate child names (case-insensitive for file system safety).
// We skip duplicates instead of failing, tracking them in stats.
let mut child_name_counts: HashMap<String, usize> = HashMap::new();
@ -220,10 +239,23 @@ pub fn syncback_dir_no_meta<'sync>(
continue;
}
// This child exists in both doms. Pass it on.
children.push(snapshot.with_joined_path(*new_child_ref, Some(old_child.id()))?);
let (child_snap, _needs_meta) = snapshot.with_joined_path(
*new_child_ref,
Some(old_child.id()),
&taken_names,
)?;
if let Some(name) = child_snap.path.file_name().and_then(|n| n.to_str()) {
taken_names.insert(name.to_lowercase());
}
children.push(child_snap);
} else {
// The child only exists in the the new dom
children.push(snapshot.with_joined_path(*new_child_ref, None)?);
let (child_snap, _needs_meta) =
snapshot.with_joined_path(*new_child_ref, None, &taken_names)?;
if let Some(name) = child_snap.path.file_name().and_then(|n| n.to_str()) {
taken_names.insert(name.to_lowercase());
}
children.push(child_snap);
}
}
// Any children that are in the old dom but not the new one are removed.
@ -267,7 +299,12 @@ pub fn syncback_dir_no_meta<'sync>(
if snapshot.should_ignore_tree(*new_child_ref) {
continue;
}
children.push(snapshot.with_joined_path(*new_child_ref, None)?);
let (child_snap, _needs_meta) =
snapshot.with_joined_path(*new_child_ref, None, &taken_names)?;
if let Some(name) = child_snap.path.file_name().and_then(|n| n.to_str()) {
taken_names.insert(name.to_lowercase());
}
children.push(child_snap);
}
}
let mut fs_snapshot = FsSnapshot::new();

View file

@ -35,20 +35,14 @@ pub fn snapshot_json_model(
format!("File is not a valid JSON model: {}", path.display())
})?;
if let Some(top_level_name) = &instance.name {
let new_name = format!("{}.model.json5", top_level_name);
// If the JSON has a name property, preserve it in metadata for syncback
let specified_name = instance.name.clone();
log::warn!(
"Model at path {} had a top-level Name field. \
This field has been ignored since Rojo 6.0.\n\
Consider removing this field and renaming the file to {}.",
new_name,
path.display()
);
// Use the name from JSON if present, otherwise fall back to filename-derived name
if instance.name.is_none() {
instance.name = Some(name.to_owned());
}
instance.name = Some(name.to_owned());
let id = instance.id.take().map(RojoRef::new);
let schema = instance.schema.take();
@ -62,7 +56,8 @@ pub fn snapshot_json_model(
.relevant_paths(vec![vfs.canonicalize(path)?])
.context(context)
.specified_id(id)
.schema(schema);
.schema(schema)
.specified_name(specified_name);
Ok(Some(snapshot))
}
@ -81,6 +76,7 @@ pub fn syncback_json_model<'sync>(
// schemas will ever exist in one project for it to matter, but it
// could have a performance cost.
model.schema = old_inst.metadata().schema.clone();
model.name = old_inst.metadata().specified_name.clone();
}
let serialized = match crate::json::to_vec_pretty_sorted(&model) {

View file

@ -8,9 +8,8 @@ use rbx_dom_weak::{
};
use crate::{
path_encoding::encode_path_name,
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
syncback::{FsSnapshot, SyncbackReturn, SyncbackSnapshot},
syncback::{name_needs_slugify, slugify_name, FsSnapshot, SyncbackReturn, SyncbackSnapshot},
};
use super::{
@ -165,10 +164,11 @@ pub fn syncback_lua<'sync>(
.or_else(|| file_stem.strip_suffix(".legacy"))
.unwrap_or(file_stem);
let meta_name = if meta_name.is_empty() {
if snapshot.encode_windows_invalid_chars() {
encode_path_name(&new_inst.name)
let instance_name = &new_inst.name;
if name_needs_slugify(instance_name) {
slugify_name(instance_name)
} else {
new_inst.name.clone()
instance_name.clone()
}
} else {
meta_name.to_string()

View file

@ -10,7 +10,10 @@ use rbx_dom_weak::{
use serde::{Deserialize, Serialize};
use crate::{
json, resolution::UnresolvedValue, snapshot::InstanceSnapshot, syncback::SyncbackSnapshot,
json,
resolution::UnresolvedValue,
snapshot::InstanceSnapshot,
syncback::{name_needs_slugify, SyncbackSnapshot},
RojoRef,
};
@ -36,6 +39,9 @@ pub struct AdjacentMetadata {
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub attributes: IndexMap<String, UnresolvedValue>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip)]
pub path: PathBuf,
}
@ -52,9 +58,8 @@ impl AdjacentMetadata {
_name: &str,
snapshot: &mut InstanceSnapshot,
) -> anyhow::Result<()> {
// Use the file stem from the actual path (which has encoded chars)
// rather than the decoded name, so meta files are found correctly
// when encodeWindowsInvalidChars is enabled.
// Use the file stem from the actual path (which may be slugified)
// rather than the instance name, so meta files are found correctly.
// Strip known script type suffixes to get the base name for the meta file.
let file_stem = path.file_stem().and_then(|s| s.to_str()).unwrap_or("");
let base_name = file_stem
@ -156,6 +161,24 @@ impl AdjacentMetadata {
}
}
let name = snapshot
.old_inst()
.and_then(|inst| inst.metadata().specified_name.clone())
.or_else(|| {
// If this is a new instance and its name is invalid for the filesystem,
// we need to specify the name in meta.json so it can be preserved
if snapshot.old_inst().is_none() {
let instance_name = &snapshot.new_inst().name;
if name_needs_slugify(instance_name) {
Some(instance_name.clone())
} else {
None
}
} else {
None
}
});
Ok(Some(Self {
ignore_unknown_instances: if ignore_unknown_instances {
Some(true)
@ -164,6 +187,7 @@ impl AdjacentMetadata {
},
properties,
attributes,
name,
path,
id: None,
schema,
@ -225,11 +249,26 @@ impl AdjacentMetadata {
Ok(())
}
fn apply_name(&mut self, snapshot: &mut InstanceSnapshot) -> anyhow::Result<()> {
if self.name.is_some() && snapshot.metadata.specified_name.is_some() {
anyhow::bail!(
"cannot specify a name using {} (instance has a name from somewhere else)",
self.path.display()
);
}
if let Some(name) = &self.name {
snapshot.name = name.clone().into();
}
snapshot.metadata.specified_name = self.name.take();
Ok(())
}
pub fn apply_all(&mut self, snapshot: &mut InstanceSnapshot) -> anyhow::Result<()> {
self.apply_ignore_unknown_instances(snapshot);
self.apply_properties(snapshot)?;
self.apply_id(snapshot)?;
self.apply_schema(snapshot)?;
self.apply_name(snapshot)?;
Ok(())
}
@ -238,11 +277,13 @@ impl AdjacentMetadata {
///
/// - The number of properties and attributes is 0
/// - `ignore_unknown_instances` is None
/// - `name` is None
#[inline]
pub fn is_empty(&self) -> bool {
self.attributes.is_empty()
&& self.properties.is_empty()
&& self.ignore_unknown_instances.is_none()
&& self.name.is_none()
}
// TODO: Add method to allow selectively applying parts of metadata and
@ -274,6 +315,9 @@ pub struct DirectoryMetadata {
#[serde(skip_serializing_if = "Option::is_none")]
pub class_name: Option<Ustr>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip)]
pub path: PathBuf,
}
@ -383,6 +427,24 @@ impl DirectoryMetadata {
}
}
let name = snapshot
.old_inst()
.and_then(|inst| inst.metadata().specified_name.clone())
.or_else(|| {
// If this is a new instance and its name is invalid for the filesystem,
// we need to specify the name in meta.json so it can be preserved
if snapshot.old_inst().is_none() {
let instance_name = &snapshot.new_inst().name;
if name_needs_slugify(instance_name) {
Some(instance_name.clone())
} else {
None
}
} else {
None
}
});
Ok(Some(Self {
ignore_unknown_instances: if ignore_unknown_instances {
Some(true)
@ -392,6 +454,7 @@ impl DirectoryMetadata {
properties,
attributes,
class_name: None,
name,
path,
id: None,
schema,
@ -404,6 +467,7 @@ impl DirectoryMetadata {
self.apply_properties(snapshot)?;
self.apply_id(snapshot)?;
self.apply_schema(snapshot)?;
self.apply_name(snapshot)?;
Ok(())
}
@ -475,17 +539,34 @@ impl DirectoryMetadata {
snapshot.metadata.schema = self.schema.take();
Ok(())
}
fn apply_name(&mut self, snapshot: &mut InstanceSnapshot) -> anyhow::Result<()> {
if self.name.is_some() && snapshot.metadata.specified_name.is_some() {
anyhow::bail!(
"cannot specify a name using {} (instance has a name from somewhere else)",
self.path.display()
);
}
if let Some(name) = &self.name {
snapshot.name = name.clone().into();
}
snapshot.metadata.specified_name = self.name.take();
Ok(())
}
/// Returns whether the metadata is 'empty', meaning it doesn't have anything
/// worth persisting in it. Specifically:
///
/// - The number of properties and attributes is 0
/// - `ignore_unknown_instances` is None
/// - `class_name` is either None or not Some("Folder")
/// - `name` is None
#[inline]
pub fn is_empty(&self) -> bool {
self.attributes.is_empty()
&& self.properties.is_empty()
&& self.ignore_unknown_instances.is_none()
&& self.name.is_none()
&& if let Some(class) = &self.class_name {
class == "Folder"
} else {

View file

@ -30,7 +30,6 @@ use serde::{Deserialize, Serialize};
use crate::{
glob::Glob,
path_encoding::decode_path_name,
project::DEFAULT_PROJECT_NAMES,
syncback::{SyncbackReturn, SyncbackSnapshot},
};
@ -72,19 +71,17 @@ pub fn snapshot_from_vfs(
if meta.is_dir() {
let (middleware, dir_name, init_path) = get_dir_middleware(vfs, path)?;
// Decode directory name if the flag is set
let decoded_name = if context.decode_windows_invalid_chars {
decode_path_name(dir_name)
} else {
dir_name.to_string()
};
// The directory name is used as-is from the filesystem.
// If a different instance name is desired, it comes from the
// `name` field in init.meta.json / init.meta.json5 (applied later
// by DirectoryMetadata::apply_name).
// TODO: Support user defined init paths
// If and when we do, make sure to go support it in
// `Project::set_file_name`, as right now it special-cases
// `default.project.json5` as an `init` path.
match middleware {
Middleware::Dir => middleware.snapshot(context, vfs, path, &decoded_name),
_ => middleware.snapshot(context, vfs, &init_path, &decoded_name),
Middleware::Dir => middleware.snapshot(context, vfs, path, dir_name),
_ => middleware.snapshot(context, vfs, &init_path, dir_name),
}
} else {
let file_name = path
@ -166,23 +163,17 @@ fn snapshot_from_path(
vfs: &Vfs,
path: &Path,
) -> anyhow::Result<Option<InstanceSnapshot>> {
// Helper to decode name if the flag is set
let decode_name = |name: &str| -> String {
if context.decode_windows_invalid_chars {
decode_path_name(name)
} else {
name.to_string()
}
};
// File names are used as-is from the filesystem. If a different instance
// name is needed (e.g. for names with special chars), it comes from the
// `name` field in adjacent .meta.json / .model.json files.
if let Some(rule) = context.get_user_sync_rule(path) {
let name = decode_name(rule.file_name_for_path(path)?);
return rule.middleware.snapshot(context, vfs, path, &name);
let name = rule.file_name_for_path(path)?;
return rule.middleware.snapshot(context, vfs, path, name);
} else {
for rule in default_sync_rules() {
if rule.matches(path) {
let name = decode_name(rule.file_name_for_path(path)?);
return rule.middleware.snapshot(context, vfs, path, &name);
let name = rule.file_name_for_path(path)?;
return rule.middleware.snapshot(context, vfs, path, name);
}
}
}

View file

@ -647,6 +647,14 @@ pub fn syncback_project<'sync>(
// All of the children in this loop are by their nature not in the
// project, so we just need to run syncback on them.
//
// Track taken names per parent directory so siblings under the same
// parent deduplicate against each other (and against existing files).
let mut taken_names_per_dir: std::collections::HashMap<
std::path::PathBuf,
std::collections::HashSet<String>,
> = std::collections::HashMap::new();
for (name, new_child) in new_child_map.drain() {
// Skip instances of ignored classes
if snapshot.should_ignore_class(&new_child.class) {
@ -680,11 +688,38 @@ pub fn syncback_project<'sync>(
// concern with directories because they're singular things,
// files that contain their own children.
if parent_middleware != Middleware::Project {
descendant_snapshots.push(snapshot.with_base_path(
let taken_names = taken_names_per_dir
.entry(parent_path.clone())
.or_insert_with(|| {
// Seed with existing files on disk so new children
// don't collide with files already present.
vfs.read_dir(&parent_path)
.ok()
.map(|entries| {
entries
.filter_map(|e| e.ok())
.filter_map(|e| {
e.path()
.file_name()
.and_then(|n| n.to_str())
.map(|n| n.to_lowercase())
})
.collect()
})
.unwrap_or_default()
});
let (child_snap, _needs_meta) = snapshot.with_base_path(
&parent_path,
new_child.referent(),
None,
)?);
taken_names,
)?;
if let Some(file_name) =
child_snap.path.file_name().and_then(|n| n.to_str())
{
taken_names.insert(file_name.to_lowercase());
}
descendant_snapshots.push(child_snap);
}
}
}

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.csv
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -19,8 +19,7 @@ metadata:
- /root/init.server.lua
- /root/init.client.lua
- /root/init.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -19,8 +19,7 @@ metadata:
- /root/init.server.lua
- /root/init.client.lua
- /root/init.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.csv
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -19,8 +19,7 @@ metadata:
- /foo/init.server.lua
- /foo/init.client.lua
- /foo/init.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -19,8 +19,7 @@ metadata:
- /foo/init.server.lua
- /foo/init.client.lua
- /foo/init.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~
@ -45,8 +44,7 @@ children:
- /foo/Child/init.server.lua
- /foo/Child/init.client.lua
- /foo/Child/init.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: dir
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.json5
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.json5
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
Path: /foo.model.json5
relevant_paths:
- /foo.model.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~
@ -24,8 +23,7 @@ children:
metadata:
ignore_unknown_instances: false
relevant_paths: []
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
Path: /foo.model.json5
relevant_paths:
- /foo.model.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~
@ -24,8 +23,7 @@ children:
metadata:
ignore_unknown_instances: false
relevant_paths: []
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.client.luau
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -19,8 +19,7 @@ metadata:
- /root/init.server.lua
- /root/init.client.lua
- /root/init.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -19,8 +19,7 @@ metadata:
- /root/init.server.lua
- /root/init.client.lua
- /root/init.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.legacy.luau
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.local.luau
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.luau
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.luau
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.plugin.luau
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /bar.server.luau
- /bar.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.server.luau
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.server.luau
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
- /foo/bar.meta.json
- /foo/bar.meta.jsonc
- /foo/bar.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -7,8 +7,7 @@ metadata:
ignore_unknown_instances: false
relevant_paths:
- /foo/bar.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
- /foo/bar.meta.json
- /foo/bar.meta.jsonc
- /foo/bar.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
- /foo/init.meta.json
- /foo/init.meta.jsonc
- /foo/init.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -7,8 +7,7 @@ metadata:
ignore_unknown_instances: false
relevant_paths:
- /foo/init.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
- /foo/init.meta.json
- /foo/init.meta.jsonc
- /foo/init.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
Path: /foo/default.project.json5
relevant_paths:
- /foo/default.project.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
Path: /foo/hello.project.json5
relevant_paths:
- /foo/hello.project.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo/other.project.json5
- /foo/default.project.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: project
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
Path: /foo.project.json5
relevant_paths:
- /foo.project.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~
@ -29,8 +28,7 @@ children:
$className: Model
parent_class: Folder
relevant_paths: []
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo/other.project.json5
- /foo/default.project.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: project
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo/other.project.json5
- /foo/default.project.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: project
schema: ~
@ -30,8 +29,7 @@ children:
$className: Model
parent_class: Folder
relevant_paths: []
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -11,8 +11,7 @@ metadata:
- /foo/other.txt
- /foo/other.meta.json5
- /foo/default.project.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: text
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
Path: /foo.project.json5
relevant_paths:
- /foo.project.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -9,8 +9,7 @@ metadata:
Path: /foo.project.json5
relevant_paths:
- /foo.project.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.toml
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- foo.toml
- foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.txt
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.txt
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- /foo.yaml
- /foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: ~
middleware: ~
schema: ~

View file

@ -10,8 +10,7 @@ metadata:
relevant_paths:
- foo.yaml
- foo.meta.json5
context:
decode_windows_invalid_chars: true
context: {}
specified_id: manually specified
middleware: ~
schema: ~

View file

@ -6,9 +6,8 @@ use rbx_dom_weak::types::Variant;
use rbx_dom_weak::ustr;
use crate::{
path_encoding::encode_path_name,
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
syncback::{FsSnapshot, SyncbackReturn, SyncbackSnapshot},
syncback::{name_needs_slugify, slugify_name, FsSnapshot, SyncbackReturn, SyncbackSnapshot},
};
use super::{meta_file::AdjacentMetadata, PathExt as _};
@ -59,10 +58,11 @@ pub fn syncback_txt<'sync>(
if !meta.is_empty() {
let parent = snapshot.path.parent_err()?;
let meta_name = if snapshot.encode_windows_invalid_chars() {
encode_path_name(&new_inst.name)
let instance_name = &new_inst.name;
let meta_name = if name_needs_slugify(instance_name) {
slugify_name(instance_name)
} else {
new_inst.name.clone()
instance_name.clone()
};
fs_snapshot.add_file(
parent.join(format!("{}.meta.json5", meta_name)),

File diff suppressed because it is too large Load diff

View file

@ -29,7 +29,10 @@ use crate::{
Project,
};
pub use file_names::{extension_for_middleware, name_for_inst, validate_file_name};
pub use file_names::{
deduplicate_name, extension_for_middleware, name_for_inst, name_needs_slugify, slugify_name,
validate_file_name,
};
pub use fs_snapshot::FsSnapshot;
pub use hash::*;
pub use property_filter::{
@ -996,12 +999,6 @@ pub struct SyncbackRules {
/// generally a better UX.
#[serde(skip_serializing_if = "Option::is_none")]
create_ignore_dir_paths: Option<bool>,
/// Whether to encode Windows-invalid characters in file names during
/// syncback. Characters like `<`, `>`, `:`, `"`, `/`, `\`, `|`, `?`, `*`
/// will be encoded as `%LT%`, `%GT%`, `%COLON%`, etc.
/// Defaults to `true`.
#[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.
@ -1054,13 +1051,6 @@ impl SyncbackRules {
Ok(globs)
}
/// Returns whether special characters (including periods) should be encoded
/// in file names during syncback. Defaults to `true`.
#[inline]
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 `true`.

View file

@ -1,5 +1,6 @@
use indexmap::IndexMap;
use memofs::Vfs;
use std::collections::HashSet;
use std::path::{Path, PathBuf};
use crate::{
@ -56,7 +57,12 @@ impl<'sync> SyncbackSnapshot<'sync> {
/// In clean mode (incremental=false), old_ref is ignored and set to None,
/// ensuring fresh filenames and middleware choices for all children.
#[inline]
pub fn with_joined_path(&self, new_ref: Ref, old_ref: Option<Ref>) -> anyhow::Result<Self> {
pub fn with_joined_path(
&self,
new_ref: Ref,
old_ref: Option<Ref>,
taken_names: &HashSet<String>,
) -> anyhow::Result<(Self, bool)> {
// In clean mode, ignore old_ref to ensure fresh structure
let effective_old_ref = if self.data.incremental { old_ref } else { None };
let mut snapshot = Self {
@ -67,16 +73,15 @@ impl<'sync> SyncbackSnapshot<'sync> {
middleware: None,
};
let middleware = get_best_middleware(&snapshot);
let encode_invalid_chars = self.encode_windows_invalid_chars();
let name = name_for_inst(
let (name, needs_meta_name) = name_for_inst(
middleware,
snapshot.new_inst(),
snapshot.old_inst(),
encode_invalid_chars,
taken_names,
)?;
snapshot.path = self.path.join(name.as_ref());
snapshot.path = self.path.join(&*name);
Ok(snapshot)
Ok((snapshot, needs_meta_name))
}
/// Constructs a SyncbackSnapshot from the provided refs and a base path,
@ -93,7 +98,8 @@ impl<'sync> SyncbackSnapshot<'sync> {
base_path: &Path,
new_ref: Ref,
old_ref: Option<Ref>,
) -> anyhow::Result<Self> {
taken_names: &HashSet<String>,
) -> anyhow::Result<(Self, bool)> {
// In clean mode, ignore old_ref to ensure fresh structure
let effective_old_ref = if self.data.incremental { old_ref } else { None };
let mut snapshot = Self {
@ -104,16 +110,15 @@ impl<'sync> SyncbackSnapshot<'sync> {
middleware: None,
};
let middleware = get_best_middleware(&snapshot);
let encode_invalid_chars = self.encode_windows_invalid_chars();
let name = name_for_inst(
let (name, needs_meta_name) = name_for_inst(
middleware,
snapshot.new_inst(),
snapshot.old_inst(),
encode_invalid_chars,
taken_names,
)?;
snapshot.path = base_path.join(name.as_ref());
snapshot.path = base_path.join(&*name);
Ok(snapshot)
Ok((snapshot, needs_meta_name))
}
/// Constructs a SyncbackSnapshot with the provided path and refs while
@ -319,18 +324,6 @@ impl<'sync> SyncbackSnapshot<'sync> {
.unwrap_or_default()
}
/// Returns whether Windows-invalid characters should be encoded in file
/// names during syncback. Defaults to `true`.
#[inline]
pub fn encode_windows_invalid_chars(&self) -> bool {
self.data
.project
.syncback_rules
.as_ref()
.map(|rules| rules.encode_windows_invalid_chars())
.unwrap_or(true)
}
/// Returns whether to emit warnings when duplicate child names are
/// encountered during syncback. Defaults to `false` (suppressed).
#[inline]

File diff suppressed because it is too large Load diff