diff --git a/server/Cargo.lock b/server/Cargo.lock index 9211b849..3242e81a 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -698,7 +698,6 @@ version = "0.5.0" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "notify 4.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/server/Cargo.toml b/server/Cargo.toml index 52036fef..21cf0ba5 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -27,7 +27,6 @@ serde_json = "1.0" notify = "4.0" rand = "0.4" regex = "1.0" -lazy_static = "1.0" log = "0.4" env_logger = "0.5" rbx-tree = { git = "https://github.com/LPGhatguy/rbx-tree.git" } diff --git a/server/src/bin.rs b/server/src/bin.rs index da27fcbc..d8783082 100644 --- a/server/src/bin.rs +++ b/server/src/bin.rs @@ -4,10 +4,20 @@ extern crate env_logger; extern crate librojo; -use std::path::{Path, PathBuf}; -use std::process; +use std::{ + path::{Path, PathBuf}, + process, + env, +}; -use librojo::pathext::canonicalish; +fn make_path_absolute(value: &Path) -> PathBuf { + if value.is_absolute() { + PathBuf::from(value) + } else { + let current_dir = env::current_dir().unwrap(); + current_dir.join(value) + } +} fn main() { env_logger::Builder::from_default_env() @@ -36,7 +46,7 @@ fn main() { ("init", sub_matches) => { let sub_matches = sub_matches.unwrap(); let project_path = Path::new(sub_matches.value_of("PATH").unwrap_or(".")); - let full_path = canonicalish(project_path); + let full_path = make_path_absolute(project_path); librojo::commands::init(&full_path); }, @@ -44,7 +54,7 @@ fn main() { let sub_matches = sub_matches.unwrap(); let project_path = match sub_matches.value_of("PROJECT") { - Some(v) => canonicalish(PathBuf::from(v)), + Some(v) => make_path_absolute(Path::new(v)), None => std::env::current_dir().unwrap(), }; diff --git a/server/src/id.rs b/server/src/id.rs deleted file mode 100644 index 98144cfa..00000000 --- a/server/src/id.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::sync::atomic::{AtomicUsize, Ordering}; - -/// A unique identifier, not guaranteed to be generated in any order. -pub type Id = usize; - -lazy_static! { - static ref LAST_ID: AtomicUsize = AtomicUsize::new(0); -} - -/// Generate a new ID, which has no defined ordering. -pub fn get_id() -> Id { - LAST_ID.fetch_add(1, Ordering::SeqCst) -} - -#[test] -fn it_gives_unique_numbers() { - let a = get_id(); - let b = get_id(); - - assert!(a != b); -} \ No newline at end of file diff --git a/server/src/lib.rs b/server/src/lib.rs index 4f1e9375..ca15e9a3 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1,4 +1,3 @@ -#[macro_use] extern crate lazy_static; #[macro_use] extern crate log; #[macro_use] extern crate rouille; #[macro_use] extern crate serde_derive; @@ -16,14 +15,10 @@ extern crate tempfile; // pub mod roblox_studio; pub mod commands; pub mod message_queue; -pub mod pathext; pub mod project; pub mod rbx_session; pub mod session; pub mod session_id; pub mod vfs; pub mod web; -pub mod web_util; - -// TODO: Remove -pub mod id; \ No newline at end of file +pub mod web_util; \ No newline at end of file diff --git a/server/src/message_queue.rs b/server/src/message_queue.rs index 1029c7e1..75c4ab2f 100644 --- a/server/src/message_queue.rs +++ b/server/src/message_queue.rs @@ -1,19 +1,37 @@ -use std::collections::HashMap; -use std::sync::{mpsc, RwLock, Mutex}; +use std::{ + collections::HashMap, + sync::{ + mpsc, + atomic::{AtomicUsize, Ordering}, + RwLock, + Mutex, + }, +}; -use id::{Id, get_id}; +use rbx_tree::RbxId; + +/// A unique identifier, not guaranteed to be generated in any order. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct ListenerId(usize); + +/// Generate a new ID, which has no defined ordering. +pub fn get_listener_id() -> ListenerId { + static LAST_ID: AtomicUsize = AtomicUsize::new(0); + + ListenerId(LAST_ID.fetch_add(1, Ordering::SeqCst)) +} #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(tag = "type")] pub enum Message { InstanceChanged { - id: Id, + id: RbxId, }, } pub struct MessageQueue { messages: RwLock>, - message_listeners: Mutex>>, + message_listeners: Mutex>>, } impl MessageQueue { @@ -39,8 +57,8 @@ impl MessageQueue { } } - pub fn subscribe(&self, sender: mpsc::Sender<()>) -> Id { - let id = get_id(); + pub fn subscribe(&self, sender: mpsc::Sender<()>) -> ListenerId { + let id = get_listener_id(); { let mut message_listeners = self.message_listeners.lock().unwrap(); @@ -50,7 +68,7 @@ impl MessageQueue { id } - pub fn unsubscribe(&self, id: Id) { + pub fn unsubscribe(&self, id: ListenerId) { { let mut message_listeners = self.message_listeners.lock().unwrap(); message_listeners.remove(&id); diff --git a/server/src/pathext.rs b/server/src/pathext.rs deleted file mode 100644 index 0b257cc8..00000000 --- a/server/src/pathext.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::env::current_dir; -use std::path::{Path, PathBuf}; - -/// Turns the path into an absolute one, using the current working directory if -/// necessary. -pub fn canonicalish>(value: T) -> PathBuf { - let cwd = current_dir().unwrap(); - - absoluteify(&cwd, value) -} - -/// Converts the given path to be absolute if it isn't already using a given -/// root. -fn absoluteify(root: A, value: B) -> PathBuf -where - A: AsRef, - B: AsRef, -{ - let root = root.as_ref(); - let value = value.as_ref(); - - if value.is_absolute() { - PathBuf::from(value) - } else { - root.join(value) - } -} \ No newline at end of file diff --git a/server/src/rbx_session.rs b/server/src/rbx_session.rs index 427f490e..db4608bf 100644 --- a/server/src/rbx_session.rs +++ b/server/src/rbx_session.rs @@ -28,11 +28,6 @@ impl RbxSession { construct_initial_tree(&project, &temp_vfs) }; - { - use serde_json; - println!("{}", serde_json::to_string(&tree).unwrap()); - } - RbxSession { tree, paths_to_ids, @@ -43,15 +38,15 @@ impl RbxSession { } pub fn path_created_or_updated(&mut self, path: &Path) { - println!("Path changed: {}", path.display()); + info!("Path changed: {}", path.display()); } pub fn path_removed(&mut self, path: &Path) { - println!("Path removed: {}", path.display()); + info!("Path removed: {}", path.display()); } pub fn path_renamed(&mut self, from_path: &Path, to_path: &Path) { - println!("Path renamed from {} to {}", from_path.display(), to_path.display()); + info!("Path renamed from {} to {}", from_path.display(), to_path.display()); } pub fn get_tree(&self) -> &RbxTree { diff --git a/server/src/session.rs b/server/src/session.rs index 53533dba..2cf03fed 100644 --- a/server/src/session.rs +++ b/server/src/session.rs @@ -71,7 +71,7 @@ impl Session { let vfs_temp = vfs.lock().unwrap(); for root in vfs_temp.get_roots() { - println!("Watching {}", root.display()); + info!("Watching path {}", root.display()); let (watch_tx, watch_rx) = mpsc::channel();