diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index c39ac28e..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore index 8ea480d4..86fbd5b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.DS_Store + # Generated by Cargo # will have compiled files and executables /target/ diff --git a/Dockerfile b/Dockerfile index d92c13ca..63b835d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,10 +2,7 @@ FROM ekidd/rust-musl-builder:nightly AS builder # Add the source code. -ADD . ./ - -# Fix permissions on source code. -RUN sudo chown -R rust:rust /home/rust +COPY --chown=rust:rust . ./ # Delete and re-install rustup in order to get the latest verison of Rust nightly. # This is necessary due to a bug in Rust: https://github.com/rust-lang-nursery/rustup.rs/issues/1239 @@ -14,17 +11,11 @@ RUN curl https://sh.rustup.rs -sSf | \ sh -s -- -y && \ rustup target add x86_64-unknown-linux-musl -WORKDIR ~ - # Build the `tdb-server` application. -RUN PKG_CONFIG_PATH=/usr/local/musl/lib/pkgconfig \ - LDFLAGS=-L/usr/local/musl/lib \ - cargo build --bin tdb-server --target x86_64-unknown-linux-musl --release +RUN cargo build --bin tdb-server --release # Build the `tdb` application. -RUN PKG_CONFIG_PATH=/usr/local/musl/lib/pkgconfig \ - LDFLAGS=-L/usr/local/musl/lib \ - cargo build --bin tdb --target x86_64-unknown-linux-musl --release +RUN cargo build --bin tdb --release # Now, we need to build the _real_ Docker container, copying in `tdb-server` FROM alpine:latest diff --git a/bins/tdb/interactive.rs b/bins/tdb/interactive.rs index 045b26de..52abdbe1 100644 --- a/bins/tdb/interactive.rs +++ b/bins/tdb/interactive.rs @@ -118,7 +118,7 @@ pub fn run(cli: &mut TectonicClient) -> io::Result<()> { _ => { match cli.cmd(&line) { Err(e) => { - println!("{}", e.description()); + println!("{}", e); } Ok(msg) => { println!("{}", msg); diff --git a/crates/tdb-cli/src/client.rs b/crates/tdb-cli/src/client.rs index 8164c791..58814968 100644 --- a/crates/tdb-cli/src/client.rs +++ b/crates/tdb-cli/src/client.rs @@ -74,8 +74,8 @@ impl TectonicClient { let res = std::str::from_utf8(&buf).unwrap().to_owned(); if success { Ok(res) - } else if res.contains("ERR: DB") { - let book_name = res.split(" ").nth(2).unwrap(); + } else if res.starts_with("ERR: No db named") { + let book_name = res.split(" ").nth(4).unwrap(); Err(TectonicError::DBNotFoundError(book_name.to_owned())) } else { Err(TectonicError::ServerError(res)) diff --git a/crates/tdb-server-core/src/handler.rs b/crates/tdb-server-core/src/handler.rs index 2b0b95cb..f0dd34c1 100644 --- a/crates/tdb-server-core/src/handler.rs +++ b/crates/tdb-server-core/src/handler.rs @@ -29,6 +29,11 @@ impl ReturnType { { ReturnType::Error(string.into()) } + + pub fn missing_db(db_name: &BookName) -> ReturnType { + //NB On change update match in client as well + ReturnType::error(format!("No db named {}", db_name)) + } } @@ -226,7 +231,7 @@ mod tests { addr )); assert_eq!( - ReturnType::Error("DB bnc_btc_eth not found.".into()), + ReturnType::Error("No db named bnc_btc_eth".into()), resp ); } diff --git a/crates/tdb-server-core/src/state.rs b/crates/tdb-server-core/src/state.rs index c5494adc..8a76e3f3 100644 --- a/crates/tdb-server-core/src/state.rs +++ b/crates/tdb-server-core/src/state.rs @@ -272,17 +272,19 @@ impl TectonicServer { .unwrap_or_else(|| Arc::clone(&self.conn(addr).unwrap().book_entry)); match self.insert(up, &book_name).await { Some(()) => ReturnType::string(""), - None => ReturnType::Error(Cow::Owned(format!("DB {} not found.", &book_name))), + None => ReturnType::missing_db(&book_name), } } Insert(None, _) => ReturnType::error("Unable to parse line"), - Create(dbname) => match self.create(&dbname) { + Create(dbname) => { + match self.create(&dbname) { Some(()) => ReturnType::string(format!("Created orderbook `{}`.", &dbname)), None => ReturnType::error(format!("Unable to create orderbook `{}`.", &dbname)), - }, + } + } Subscribe(dbname) => { self.sub(&dbname, addr); - ReturnType::string(format!("Subscribed to {}", dbname)) + ReturnType::string(format!("Subscribed to {}", &dbname)) } // Subscription => { // let message = state.rx.as_ref().unwrap().try_recv(); @@ -303,20 +305,20 @@ impl TectonicServer { Load(dbname) => { match self.load_db(&dbname, addr) { Some(_) => ReturnType::string(format!("Loaded orderbook `{}`.", &dbname)), - None => ReturnType::error(format!("No db named `{}`", dbname)), + None => ReturnType::missing_db(&dbname), } } Use(dbname) => { match self.use_db(&dbname, addr) { Some(_) => ReturnType::string(format!("SWITCHED TO orderbook `{}`.", &dbname)), - None => ReturnType::error(format!("No db named `{}`", dbname)), + None => ReturnType::missing_db(&dbname), } } Exists(dbname) => { if self.exists(&dbname) { ReturnType::ok() } else { - ReturnType::error(format!("No db named `{}`", dbname)) + ReturnType::missing_db(&dbname) } } Get(cnt, fmt, rng, loc) =>