Skip to content

Commit

Permalink
rojo-keep and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Corecii committed Sep 6, 2023
1 parent dbb0f44 commit 69a0f8b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/cli/syncback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ use std::{

use crate::{
open_tree::{open_tree_at_location, InputTree},
snapshot::{RojoTree},
snapshot::RojoTree,
};
use anyhow::{bail};
use anyhow::bail;
use clap::Parser;

use memofs::Vfs;
use rbx_dom_weak::WeakDom;

use super::resolve_path;

const UNKNOWN_INPUT_KIND_ERR: &str = "Could not detect what kind of file to sync from. \
Expected output file to end in .rbxl, .rbxlx, .rbxm, or .rbxmx.";

/// Syncs changes back to the filesystem from a model or place file.
#[derive(Debug, Parser)]
pub struct SyncbackCommand {
Expand Down
51 changes: 48 additions & 3 deletions src/snapshot_middleware/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,33 @@ impl SnapshotMiddleware for DirectoryMiddleware {
instance: &Instance,
consider_descendants: bool,
) -> Option<i32> {
let is_preferred_class = preferred_classes().contains(instance.class.as_str());

// Directory representation is not an option if we have more than one
// child with the same name
let mut names = HashSet::new();
for child_ref in instance.children() {
let inst = dom.get_by_ref(*child_ref).unwrap();
let name = inst.name.as_str();
if !names.insert(name.to_lowercase()) {
log::info!("Cannot save {} as a directory because it contains 2+ children with the same name: {} (it will be saved as something else instead, like an rbxm)", instance.name, name);
if is_preferred_class && consider_descendants {
log::info!("Cannot save {} as a directory because it contains 2+ children with the same name: {} (it will be saved as something else instead, like an rbxm)", instance.name, name);
} else {
log::debug!("Cannot save {} as a directory because it contains 2+ children with the same name: {} (it will be saved as something else instead, like an rbxm)", instance.name, name);
}
return None;
}
if !is_filename_legal_everywhere(name) {
log::info!("Cannot save {} as a directory because it contains a child with an invalid name: {} (it will be saved as something else instead, like an rbxm)", instance.name, name);
if is_preferred_class && consider_descendants {
log::info!("Cannot save {} as a directory because it contains a child with an invalid name: {} (it will be saved as something else instead, like an rbxm)", instance.name, name);
} else {
log::debug!("Cannot save {} as a directory because it contains a child with an invalid name: {} (it will be saved as something else instead, like an rbxm)", instance.name, name);
}
return None;
}
}

if preferred_classes().contains(instance.class.as_str()) {
if is_preferred_class {
if consider_descendants {
Some(PRIORITY_MANY_READABLE)
} else {
Expand Down Expand Up @@ -285,6 +295,29 @@ fn syncback_update(sync: &SyncbackArgs<'_, '_>) -> anyhow::Result<SyncbackNode>
}
}

if new_inst.name == "Vehicles" {
println!(
"DEBUG VEHICLES: {} {} {}",
new_inst.class == "Folder",
fs_snapshot.files.is_empty(),
new_inst.children().is_empty()
);
println!(
"DEBUG VEHICLES : {} {:?} {}",
new_inst.class,
fs_snapshot.files,
new_inst.children().len()
);
}

if new_inst.class == "Folder" {
if fs_snapshot.files.is_empty() && new_inst.children().is_empty() {
fs_snapshot
.files
.insert(path.join(".rojo-keep"), Some(Arc::new(Vec::new())));
}
}

metadata.fs_snapshot = Some(fs_snapshot);

Ok(SyncbackNode::new(
Expand Down Expand Up @@ -462,6 +495,14 @@ fn syncback_new(sync: &SyncbackArgs<'_, '_>) -> anyhow::Result<SyncbackNode> {
}
}

if new_inst.class == "Folder" {
if fs_snapshot.files.is_empty() && new_inst.children().is_empty() {
fs_snapshot
.files
.insert(path.join(".rojo-keep"), Some(Arc::new(Vec::new())));
}
}

metadata.fs_snapshot = Some(fs_snapshot);

Ok(SyncbackNode::new(
Expand Down Expand Up @@ -673,6 +714,10 @@ pub fn snapshot_dir_no_meta(
let fs_snapshot = snapshot.metadata.fs_snapshot.as_mut().unwrap();
fs_snapshot.dirs.insert(path.to_path_buf());

// ensure .rojo-keep is deleted if we syncback and it's not needed anymore.
// it does not matter if it was actually present in the first place.
fs_snapshot.files.insert(path.join(".rojo-keep"), None);

Ok(Some(snapshot))
}

Expand Down

0 comments on commit 69a0f8b

Please sign in to comment.