From 214ed0abbadb1d2abc95435bbd2560cd51052e30 Mon Sep 17 00:00:00 2001 From: Arvid Lunnemark Date: Mon, 11 Jul 2022 19:35:02 -0400 Subject: [PATCH] add update-rust-project script --- daemon/README.md | 4 +++- daemon/db/db.rs | 7 ++++++- daemon/update-rust-project.sh | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100755 daemon/update-rust-project.sh diff --git a/daemon/README.md b/daemon/README.md index d1e038e8..5d6ca33f 100644 --- a/daemon/README.md +++ b/daemon/README.md @@ -3,9 +3,11 @@ Set up VSCode rust-analyzer (very recommended!): ``` -bazelisk run @rules_rust//tools/rust_analyzer:gen_rust_project +./update-rust-project.sh ``` +Then restart the rust-analyzer server in VSCode with F1 and then searching for "Rust analyzer: restart server". + ## Database changes We want to create a migration! diff --git a/daemon/db/db.rs b/daemon/db/db.rs index 856be056..5455be5e 100644 --- a/daemon/db/db.rs +++ b/daemon/db/db.rs @@ -719,7 +719,12 @@ unsafe fn errmsg_to_string(errmsg: *const std::os::raw::c_char) -> String { impl DB { pub fn connect(&self) -> Result { match SqliteConnection::establish(&self.address) { - Ok(c) => Ok(c), + Ok(c) => { + // we sleep for up to 1000 ms while the database is locked + // we also enforce foreign key constraints + c.batch_execute("PRAGMA foreign_keys = ON; PRAGMA busy_timeout = 1000;")?; + Ok(c) + }, Err(e) => return Err(DbError::Unknown(format!("failed to connect to database, {}", e,))), } } diff --git a/daemon/update-rust-project.sh b/daemon/update-rust-project.sh new file mode 100755 index 00000000..36e30b6d --- /dev/null +++ b/daemon/update-rust-project.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +if [[ $(sd --version || true) != *"sd"* ]]; then + echo "Installing sd..." + cargo install sd +fi + +sd rust_static_library rust_library "${ANYSPHEREROOT}"/client/daemon/BUILD +bazelisk run @rules_rust//tools/rust_analyzer:gen_rust_project +sd rust_library rust_static_library "${ANYSPHEREROOT}"/client/daemon/BUILD