mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-25 04:54:07 +00:00
Refactor property filter imports and improve log formatting in ApiService
- Adjusted the import order for property filter functions for consistency. - Enhanced log formatting in the syncback logic to improve readability and maintainability. - Reformatted code for better alignment and clarity in various sections of the ApiService implementation.
This commit is contained in:
parent
dccd3a691a
commit
9dd2fd159e
2 changed files with 21 additions and 18 deletions
|
|
@ -31,7 +31,9 @@ use crate::{
|
||||||
pub use file_names::{extension_for_middleware, name_for_inst, validate_file_name};
|
pub use file_names::{extension_for_middleware, name_for_inst, validate_file_name};
|
||||||
pub use fs_snapshot::FsSnapshot;
|
pub use fs_snapshot::FsSnapshot;
|
||||||
pub use hash::*;
|
pub use hash::*;
|
||||||
pub use property_filter::{filter_properties, filter_properties_preallocated, should_property_serialize};
|
pub use property_filter::{
|
||||||
|
filter_properties, filter_properties_preallocated, should_property_serialize,
|
||||||
|
};
|
||||||
pub use snapshot::{inst_path, SyncbackData, SyncbackSnapshot};
|
pub use snapshot::{inst_path, SyncbackData, SyncbackSnapshot};
|
||||||
|
|
||||||
/// The name of an enviroment variable to use to override the behavior of
|
/// The name of an enviroment variable to use to override the behavior of
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ use rbx_dom_weak::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
serve_session::ServeSession,
|
serve_session::ServeSession,
|
||||||
snapshot::{InstigatingSource, InstanceWithMeta, PatchSet, PatchUpdate},
|
snapshot::{InstanceWithMeta, InstigatingSource, PatchSet, PatchUpdate},
|
||||||
web::{
|
web::{
|
||||||
interface::{
|
interface::{
|
||||||
ErrorResponse, Instance, InstanceMetadata, MessagesPacket, OpenResponse, ReadResponse,
|
ErrorResponse, Instance, InstanceMetadata, MessagesPacket, OpenResponse, ReadResponse,
|
||||||
|
|
@ -233,7 +233,11 @@ impl ApiService {
|
||||||
|
|
||||||
for removed_id in &request.removed {
|
for removed_id in &request.removed {
|
||||||
if let Err(err) = self.syncback_removed_instance(*removed_id, &tree) {
|
if let Err(err) = self.syncback_removed_instance(*removed_id, &tree) {
|
||||||
log::warn!("Failed to syncback removed instance {:?}: {}", removed_id, err);
|
log::warn!(
|
||||||
|
"Failed to syncback removed instance {:?}: {}",
|
||||||
|
removed_id,
|
||||||
|
err
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -490,19 +494,12 @@ impl ApiService {
|
||||||
// Delete the file or directory
|
// Delete the file or directory
|
||||||
if instance_path.is_dir() {
|
if instance_path.is_dir() {
|
||||||
fs::remove_dir_all(instance_path).with_context(|| {
|
fs::remove_dir_all(instance_path).with_context(|| {
|
||||||
format!(
|
format!("Failed to remove directory: {}", instance_path.display())
|
||||||
"Failed to remove directory: {}",
|
|
||||||
instance_path.display()
|
|
||||||
)
|
|
||||||
})?;
|
})?;
|
||||||
log::info!(
|
log::info!("Syncback: Removed directory at {}", instance_path.display());
|
||||||
"Syncback: Removed directory at {}",
|
|
||||||
instance_path.display()
|
|
||||||
);
|
|
||||||
} else if instance_path.is_file() {
|
} else if instance_path.is_file() {
|
||||||
fs::remove_file(instance_path).with_context(|| {
|
fs::remove_file(instance_path)
|
||||||
format!("Failed to remove file: {}", instance_path.display())
|
.with_context(|| format!("Failed to remove file: {}", instance_path.display()))?;
|
||||||
})?;
|
|
||||||
log::info!("Syncback: Removed file at {}", instance_path.display());
|
log::info!("Syncback: Removed file at {}", instance_path.display());
|
||||||
|
|
||||||
// Also remove adjacent meta file if it exists
|
// Also remove adjacent meta file if it exists
|
||||||
|
|
@ -885,7 +882,8 @@ impl ApiService {
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
|
||||||
let (properties, attributes) = self.filter_properties_for_meta(&added.class_name, &added.properties, None);
|
let (properties, attributes) =
|
||||||
|
self.filter_properties_for_meta(&added.class_name, &added.properties, None);
|
||||||
|
|
||||||
if properties.is_empty() && attributes.is_empty() {
|
if properties.is_empty() && attributes.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
@ -914,7 +912,8 @@ impl ApiService {
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
|
||||||
let (properties, attributes) = self.filter_properties_for_meta(&added.class_name, &added.properties, None);
|
let (properties, attributes) =
|
||||||
|
self.filter_properties_for_meta(&added.class_name, &added.properties, None);
|
||||||
|
|
||||||
// For non-Folder classes, we need to include className
|
// For non-Folder classes, we need to include className
|
||||||
let meta = self.build_meta_object(Some(&added.class_name), properties, attributes);
|
let meta = self.build_meta_object(Some(&added.class_name), properties, attributes);
|
||||||
|
|
@ -1145,7 +1144,8 @@ impl ApiService {
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
// Filter properties matching dedicated syncback behavior
|
// Filter properties matching dedicated syncback behavior
|
||||||
let (properties, attributes) = self.filter_properties_for_meta(&added.class_name, &added.properties, None);
|
let (properties, attributes) =
|
||||||
|
self.filter_properties_for_meta(&added.class_name, &added.properties, None);
|
||||||
|
|
||||||
// Build the JSON model structure
|
// Build the JSON model structure
|
||||||
// Format: https://rojo.space/docs/v7/sync-details/#json-models
|
// Format: https://rojo.space/docs/v7/sync-details/#json-models
|
||||||
|
|
@ -3766,7 +3766,8 @@ mod tests {
|
||||||
|
|
||||||
// Create the file
|
// Create the file
|
||||||
let mut file = File::create(&file_path).expect("Failed to create test file");
|
let mut file = File::create(&file_path).expect("Failed to create test file");
|
||||||
file.write_all(b"return {}").expect("Failed to write to file");
|
file.write_all(b"return {}")
|
||||||
|
.expect("Failed to write to file");
|
||||||
|
|
||||||
// Verify file exists
|
// Verify file exists
|
||||||
assert!(file_path.exists(), "Test file should exist before removal");
|
assert!(file_path.exists(), "Test file should exist before removal");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue