mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 12:45:05 +00:00
Move Imfs snapshotting into ImfsDebug
This commit is contained in:
@@ -40,18 +40,6 @@ impl<F: ImfsFetcher> Imfs<F> {
|
||||
self.fetcher.receiver()
|
||||
}
|
||||
|
||||
pub fn commit_pending_changes(&mut self) -> FsResult<Vec<ImfsEvent>> {
|
||||
let receiver = self.fetcher.receiver();
|
||||
let mut changes = Vec::new();
|
||||
|
||||
while let Ok(event) = receiver.try_recv() {
|
||||
self.commit_change(&event)?;
|
||||
changes.push(event);
|
||||
}
|
||||
|
||||
Ok(changes)
|
||||
}
|
||||
|
||||
pub fn commit_change(&mut self, event: &ImfsEvent) -> FsResult<()> {
|
||||
use notify::DebouncedEvent::*;
|
||||
|
||||
@@ -84,35 +72,6 @@ impl<F: ImfsFetcher> Imfs<F> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_from_snapshot(&mut self, path: impl AsRef<Path>, snapshot: ImfsSnapshot) {
|
||||
let path = path.as_ref();
|
||||
|
||||
match snapshot {
|
||||
ImfsSnapshot::File(file) => {
|
||||
self.inner.insert(
|
||||
path.to_path_buf(),
|
||||
ImfsItem::File(ImfsFile {
|
||||
path: path.to_path_buf(),
|
||||
contents: Some(file.contents),
|
||||
}),
|
||||
);
|
||||
}
|
||||
ImfsSnapshot::Directory(directory) => {
|
||||
self.inner.insert(
|
||||
path.to_path_buf(),
|
||||
ImfsItem::Directory(ImfsDirectory {
|
||||
path: path.to_path_buf(),
|
||||
children_enumerated: true,
|
||||
}),
|
||||
);
|
||||
|
||||
for (child_name, child) in directory.children.into_iter() {
|
||||
self.load_from_snapshot(path.join(child_name), child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn raise_file_changed(&mut self, path: impl AsRef<Path>) -> FsResult<()> {
|
||||
let path = path.as_ref();
|
||||
|
||||
@@ -306,6 +265,7 @@ impl<F: ImfsFetcher> Imfs<F> {
|
||||
/// Contains extra methods that should only be used for debugging. They're
|
||||
/// broken out into a separate trait to make it more explicit to depend on them.
|
||||
pub trait ImfsDebug {
|
||||
fn debug_load_snapshot<P: AsRef<Path>>(&mut self, path: P, snapshot: ImfsSnapshot);
|
||||
fn debug_is_file(&self, path: &Path) -> bool;
|
||||
fn debug_contents<'a>(&'a self, path: &Path) -> Option<&'a [u8]>;
|
||||
fn debug_children<'a>(&'a self, path: &Path) -> Option<(bool, Vec<&'a Path>)>;
|
||||
@@ -313,6 +273,35 @@ pub trait ImfsDebug {
|
||||
}
|
||||
|
||||
impl<F> ImfsDebug for Imfs<F> {
|
||||
fn debug_load_snapshot<P: AsRef<Path>>(&mut self, path: P, snapshot: ImfsSnapshot) {
|
||||
let path = path.as_ref();
|
||||
|
||||
match snapshot {
|
||||
ImfsSnapshot::File(file) => {
|
||||
self.inner.insert(
|
||||
path.to_path_buf(),
|
||||
ImfsItem::File(ImfsFile {
|
||||
path: path.to_path_buf(),
|
||||
contents: Some(file.contents),
|
||||
}),
|
||||
);
|
||||
}
|
||||
ImfsSnapshot::Directory(directory) => {
|
||||
self.inner.insert(
|
||||
path.to_path_buf(),
|
||||
ImfsItem::Directory(ImfsDirectory {
|
||||
path: path.to_path_buf(),
|
||||
children_enumerated: true,
|
||||
}),
|
||||
);
|
||||
|
||||
for (child_name, child) in directory.children.into_iter() {
|
||||
self.debug_load_snapshot(path.join(child_name), child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn debug_is_file(&self, path: &Path) -> bool {
|
||||
match self.inner.get(path) {
|
||||
Some(ImfsItem::File(_)) => true,
|
||||
@@ -432,7 +421,7 @@ mod test {
|
||||
let mut imfs = Imfs::new(NoopFetcher);
|
||||
let file = ImfsSnapshot::file("hello, world!");
|
||||
|
||||
imfs.load_from_snapshot("/hello.txt", file);
|
||||
imfs.debug_load_snapshot("/hello.txt", file);
|
||||
|
||||
let entry = imfs.get_contents("/hello.txt").unwrap();
|
||||
assert_eq!(entry, b"hello, world!");
|
||||
@@ -446,7 +435,7 @@ mod test {
|
||||
"b.lua" => ImfsSnapshot::file("contents of b.lua"),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/dir", dir);
|
||||
imfs.debug_load_snapshot("/dir", dir);
|
||||
|
||||
let children = imfs.get_children("/dir").unwrap();
|
||||
|
||||
@@ -560,7 +549,7 @@ mod test {
|
||||
let mut imfs = Imfs::new(NoopFetcher);
|
||||
|
||||
let file = ImfsSnapshot::file("hello, world!");
|
||||
imfs.load_from_snapshot("/hello.txt", file);
|
||||
imfs.debug_load_snapshot("/hello.txt", file);
|
||||
|
||||
let hello = imfs.get("/hello.txt").expect("couldn't get hello.txt");
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ fn convert_localization_csv(contents: &[u8]) -> String {
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
use crate::imfs::{ImfsSnapshot, NoopFetcher};
|
||||
use crate::imfs::{ImfsDebug, ImfsSnapshot, NoopFetcher};
|
||||
|
||||
#[test]
|
||||
fn csv_from_imfs() {
|
||||
@@ -147,7 +147,7 @@ Key,Source,Context,Example,es
|
||||
Ack,Ack!,,An exclamation of despair,¡Ay!"#,
|
||||
);
|
||||
|
||||
imfs.load_from_snapshot("/foo.csv", file);
|
||||
imfs.debug_load_snapshot("/foo.csv", file);
|
||||
|
||||
let entry = imfs.get("/foo.csv").unwrap();
|
||||
let instance_snapshot = SnapshotCsv::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||
|
||||
@@ -78,14 +78,14 @@ mod test {
|
||||
|
||||
use maplit::hashmap;
|
||||
|
||||
use crate::imfs::NoopFetcher;
|
||||
use crate::imfs::{ImfsDebug, NoopFetcher};
|
||||
|
||||
#[test]
|
||||
fn empty_folder() {
|
||||
let mut imfs = Imfs::new(NoopFetcher);
|
||||
let dir = ImfsSnapshot::dir::<String>(HashMap::new());
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo").unwrap();
|
||||
let instance_snapshot = SnapshotDir::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||
@@ -103,7 +103,7 @@ mod test {
|
||||
"Child" => ImfsSnapshot::dir::<String>(HashMap::new()),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo").unwrap();
|
||||
let instance_snapshot = SnapshotDir::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||
|
||||
@@ -136,7 +136,7 @@ mod test {
|
||||
use maplit::hashmap;
|
||||
use rbx_dom_weak::RbxValue;
|
||||
|
||||
use crate::imfs::{ImfsSnapshot, NoopFetcher};
|
||||
use crate::imfs::{ImfsDebug, ImfsSnapshot, NoopFetcher};
|
||||
|
||||
#[test]
|
||||
fn model_from_imfs() {
|
||||
@@ -159,7 +159,7 @@ mod test {
|
||||
"#,
|
||||
);
|
||||
|
||||
imfs.load_from_snapshot("/foo.model.json", file);
|
||||
imfs.debug_load_snapshot("/foo.model.json", file);
|
||||
|
||||
let entry = imfs.get("/foo.model.json").unwrap();
|
||||
let instance_snapshot = SnapshotJsonModel::from_imfs(&mut imfs, &entry)
|
||||
|
||||
@@ -141,14 +141,14 @@ mod test {
|
||||
|
||||
use maplit::hashmap;
|
||||
|
||||
use crate::imfs::{ImfsSnapshot, NoopFetcher};
|
||||
use crate::imfs::{ImfsDebug, ImfsSnapshot, NoopFetcher};
|
||||
|
||||
#[test]
|
||||
fn module_from_imfs() {
|
||||
let mut imfs = Imfs::new(NoopFetcher);
|
||||
let file = ImfsSnapshot::file("Hello there!");
|
||||
|
||||
imfs.load_from_snapshot("/foo.lua", file);
|
||||
imfs.debug_load_snapshot("/foo.lua", file);
|
||||
|
||||
let entry = imfs.get("/foo.lua").unwrap();
|
||||
let instance_snapshot = SnapshotLua::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||
@@ -170,7 +170,7 @@ mod test {
|
||||
let mut imfs = Imfs::new(NoopFetcher);
|
||||
let file = ImfsSnapshot::file("Hello there!");
|
||||
|
||||
imfs.load_from_snapshot("/foo.server.lua", file);
|
||||
imfs.debug_load_snapshot("/foo.server.lua", file);
|
||||
|
||||
let entry = imfs.get("/foo.server.lua").unwrap();
|
||||
let instance_snapshot = SnapshotLua::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||
@@ -192,7 +192,7 @@ mod test {
|
||||
let mut imfs = Imfs::new(NoopFetcher);
|
||||
let file = ImfsSnapshot::file("Hello there!");
|
||||
|
||||
imfs.load_from_snapshot("/foo.client.lua", file);
|
||||
imfs.debug_load_snapshot("/foo.client.lua", file);
|
||||
|
||||
let entry = imfs.get("/foo.client.lua").unwrap();
|
||||
let instance_snapshot = SnapshotLua::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||
|
||||
@@ -143,7 +143,7 @@ mod test {
|
||||
use maplit::hashmap;
|
||||
use rbx_dom_weak::RbxValue;
|
||||
|
||||
use crate::imfs::{ImfsSnapshot, NoopFetcher};
|
||||
use crate::imfs::{ImfsDebug, ImfsSnapshot, NoopFetcher};
|
||||
|
||||
#[test]
|
||||
fn project_from_folder() {
|
||||
@@ -161,7 +161,7 @@ mod test {
|
||||
"#),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo").unwrap();
|
||||
let instance_snapshot = SnapshotProject::from_imfs(&mut imfs, &entry)
|
||||
@@ -190,7 +190,7 @@ mod test {
|
||||
"#),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo/hello.project.json").unwrap();
|
||||
let instance_snapshot = SnapshotProject::from_imfs(&mut imfs, &entry)
|
||||
@@ -225,7 +225,7 @@ mod test {
|
||||
"#),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo").unwrap();
|
||||
let instance_snapshot = SnapshotProject::from_imfs(&mut imfs, &entry)
|
||||
@@ -264,7 +264,7 @@ mod test {
|
||||
"#),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo").unwrap();
|
||||
let instance_snapshot = SnapshotProject::from_imfs(&mut imfs, &entry)
|
||||
@@ -304,7 +304,7 @@ mod test {
|
||||
"#),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo").unwrap();
|
||||
let instance_snapshot = SnapshotProject::from_imfs(&mut imfs, &entry)
|
||||
@@ -340,7 +340,7 @@ mod test {
|
||||
"other.txt" => ImfsSnapshot::file("Hello, world!"),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo").unwrap();
|
||||
let instance_snapshot = SnapshotProject::from_imfs(&mut imfs, &entry)
|
||||
@@ -384,7 +384,7 @@ mod test {
|
||||
"#),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo").unwrap();
|
||||
let instance_snapshot = SnapshotProject::from_imfs(&mut imfs, &entry)
|
||||
@@ -425,7 +425,7 @@ mod test {
|
||||
"#),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo").unwrap();
|
||||
let instance_snapshot = SnapshotProject::from_imfs(&mut imfs, &entry)
|
||||
@@ -477,7 +477,7 @@ mod test {
|
||||
"#),
|
||||
});
|
||||
|
||||
imfs.load_from_snapshot("/foo", dir);
|
||||
imfs.debug_load_snapshot("/foo", dir);
|
||||
|
||||
let entry = imfs.get("/foo").unwrap();
|
||||
let instance_snapshot = SnapshotProject::from_imfs(&mut imfs, &entry)
|
||||
|
||||
@@ -66,14 +66,14 @@ impl SnapshotMiddleware for SnapshotRbxm {
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
use crate::imfs::{ImfsSnapshot, NoopFetcher};
|
||||
use crate::imfs::{ImfsDebug, ImfsSnapshot, NoopFetcher};
|
||||
|
||||
#[test]
|
||||
fn model_from_imfs() {
|
||||
let mut imfs = Imfs::new(NoopFetcher);
|
||||
let file = ImfsSnapshot::file(include_bytes!("../../assets/test-folder.rbxm").to_vec());
|
||||
|
||||
imfs.load_from_snapshot("/foo.rbxm", file);
|
||||
imfs.debug_load_snapshot("/foo.rbxm", file);
|
||||
|
||||
let entry = imfs.get("/foo.rbxm").unwrap();
|
||||
let instance_snapshot = SnapshotRbxm::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||
|
||||
@@ -64,7 +64,7 @@ mod test {
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::imfs::{ImfsSnapshot, NoopFetcher};
|
||||
use crate::imfs::{ImfsDebug, ImfsSnapshot, NoopFetcher};
|
||||
|
||||
#[test]
|
||||
fn model_from_imfs() {
|
||||
@@ -81,7 +81,7 @@ mod test {
|
||||
"#,
|
||||
);
|
||||
|
||||
imfs.load_from_snapshot("/foo.rbxmx", file);
|
||||
imfs.debug_load_snapshot("/foo.rbxmx", file);
|
||||
|
||||
let entry = imfs.get("/foo.rbxmx").unwrap();
|
||||
let instance_snapshot = SnapshotRbxmx::from_imfs(&mut imfs, &entry)
|
||||
|
||||
@@ -94,14 +94,14 @@ mod test {
|
||||
use maplit::hashmap;
|
||||
use rbx_dom_weak::RbxInstanceProperties;
|
||||
|
||||
use crate::imfs::NoopFetcher;
|
||||
use crate::imfs::{ImfsDebug, NoopFetcher};
|
||||
|
||||
#[test]
|
||||
fn instance_from_imfs() {
|
||||
let mut imfs = Imfs::new(NoopFetcher);
|
||||
let file = ImfsSnapshot::file("Hello there!");
|
||||
|
||||
imfs.load_from_snapshot("/foo.txt", file);
|
||||
imfs.debug_load_snapshot("/foo.txt", file);
|
||||
|
||||
let entry = imfs.get("/foo.txt").unwrap();
|
||||
let instance_snapshot = SnapshotTxt::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user