Skip to content

Commit

Permalink
run clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma committed Jan 30, 2024
1 parent 4332bb6 commit 8c0ac13
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 43 deletions.
4 changes: 2 additions & 2 deletions bindings/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub unsafe extern "C" fn libsql_prepare(
}
};
if conn.is_null() {
set_err_msg(format!("Null connection"), out_err_msg);
set_err_msg("Null connection".to_string(), out_err_msg);
return 2;
}
let conn = conn.get_ref();
Expand Down Expand Up @@ -380,7 +380,7 @@ pub unsafe extern "C" fn libsql_execute_stmt(
out_err_msg: *mut *const std::ffi::c_char,
) -> std::ffi::c_int {
if stmt.is_null() {
set_err_msg(format!("Null statement"), out_err_msg);
set_err_msg("Null statement".to_string(), out_err_msg);
return 1;
}
let stmt = stmt.get_ref_mut();
Expand Down
2 changes: 1 addition & 1 deletion libsql-ffi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub fn build_bundled(out_dir: &str, out_path: &Path) {
fn copy_multiple_ciphers(out_dir: &str, out_path: &Path) {
let dylib = format!("{BUNDLED_DIR}/SQLite3MultipleCiphers/build/libsqlite3mc_static.a");
if !Path::new(&dylib).exists() {
build_multiple_ciphers(&out_path);
build_multiple_ciphers(out_path);
}

std::fs::copy(dylib, format!("{out_dir}/libsqlite3mc.a")).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion libsql-replication/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl SnapshotFile {
pub async fn open(path: impl AsRef<Path>) -> Result<Self, Error> {
let mut file = File::open(path).await?;
let mut header = SnapshotFileHeader::new_zeroed();
file.read_exact(&mut header.as_bytes_mut()).await?;
file.read_exact(header.as_bytes_mut()).await?;

Ok(Self { file, header })
}
Expand Down
2 changes: 1 addition & 1 deletion libsql-server/src/connection/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl From<&metadata::DatabaseConfig> for DatabaseConfig {
heartbeat_url: value
.heartbeat_url
.as_ref()
.map(|s| Url::parse(&s).unwrap()),
.map(|s| Url::parse(s).unwrap()),
bottomless_db_id: value.bottomless_db_id.clone(),
jwt_key: value.jwt_key.clone(),
txn_timeout: value.txn_timeout_s.map(Duration::from_secs),
Expand Down
1 change: 0 additions & 1 deletion libsql-server/src/connection/libsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ where
rusqlite::functions::FunctionFlags::SQLITE_UTF8
| rusqlite::functions::FunctionFlags::SQLITE_DETERMINISTIC,
{
let namespace = namespace;
move |_| Ok(namespace.clone())
},
)?;
Expand Down
1 change: 1 addition & 0 deletions libsql-server/src/namespace/meta_store.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::mutable_key_type)]
use std::collections::HashMap;
use std::path::Path;
use std::sync::Arc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl ReplicationLoggerWal {
header.replication_index =
(self.logger().new_frame_notifier.borrow().unwrap_or(0) + 1).into();
#[cfg(feature = "encryption")]
let pager = libsql_sys::connection::leak_pager(_db.as_ptr());
let pager = unsafe { libsql_sys::connection::leak_pager(_db.as_ptr()) };
#[cfg(not(feature = "encryption"))]
let pager = std::ptr::null_mut();
let mut header = libsql_pghdr {
Expand Down
4 changes: 2 additions & 2 deletions libsql-server/src/rpc/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ impl ProxyService {
))),
}?;
Ok(if let Some(auth) = &self.auth {
auth.authenticate_grpc(&req, self.disable_namespaces, namespace_jwt_key)?
auth.authenticate_grpc(req, self.disable_namespaces, namespace_jwt_key)?
} else {
Authenticated::from_proxy_grpc_request(&req, self.disable_namespaces)?
Authenticated::from_proxy_grpc_request(req, self.disable_namespaces)?
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion libsql-server/src/rpc/replica_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl ReplicaProxyService {
}

async fn do_auth<T>(&self, req: &mut Request<T>) -> Result<(), Status> {
let namespace = super::extract_namespace(self.disable_namespaces, &req)?;
let namespace = super::extract_namespace(self.disable_namespaces, req)?;
let namespace_jwt_key = self.namespaces.with(namespace, |ns| ns.jwt_key()).await;
match namespace_jwt_key {
Ok(Ok(jwt_key)) => {
Expand Down
2 changes: 1 addition & 1 deletion libsql-server/src/rpc/replication_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl ReplicationLogService {
fn encode_session_token(&self, version: usize) -> Uuid {
let mut sha = Md5::new();
sha.update(&self.session_token[..]);
sha.update(&version.to_le_bytes());
sha.update(version.to_le_bytes());

let num = sha.finalize();
let num = u128::from_le_bytes(num.into());
Expand Down
2 changes: 1 addition & 1 deletion libsql-server/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl Stats {
}

pub fn id(&self) -> Option<Uuid> {
self.id.clone()
self.id
}
}

Expand Down
2 changes: 1 addition & 1 deletion libsql-server/src/test/bottomless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::Server;

const S3_URL: &str = "http://localhost:9000/";

const S3_SERVER: Once = Once::new();
static S3_SERVER: Once = Once::new();

async fn start_s3_server() {
std::env::set_var("LIBSQL_BOTTOMLESS_ENDPOINT", "http://localhost:9000");
Expand Down
1 change: 1 addition & 0 deletions libsql-server/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(dead_code)]
#![allow(clippy::mutable_key_type)]

use std::collections::HashMap;

Expand Down
12 changes: 6 additions & 6 deletions libsql-server/tests/standalone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,26 +325,26 @@ fn is_autocommit() {
let db = Database::open_remote_with_connector("http://primary:8080", "", TurmoilConnector)?;
let conn = db.connect()?;

assert_eq!(conn.is_autocommit(), true);
assert!(conn.is_autocommit());
conn.execute("create table test (x)", ()).await?;

conn.execute("begin;", ()).await?;
assert_eq!(conn.is_autocommit(), false);
assert!(!conn.is_autocommit());
conn.execute("insert into test values (12);", ()).await?;
conn.execute("commit;", ()).await?;
assert_eq!(conn.is_autocommit(), true);
assert!(conn.is_autocommit());

// make an explicit transaction
{
let tx = conn.transaction().await?;
assert_eq!(tx.is_autocommit(), false);
assert_eq!(conn.is_autocommit(), true); // connection is still autocommit
assert!(!tx.is_autocommit());
assert!(conn.is_autocommit()); // connection is still autocommit

tx.execute("insert into test values (12);", ()).await?;
// transaction rolls back
}

assert_eq!(conn.is_autocommit(), true);
assert!(conn.is_autocommit());

let mut rows = conn.query("select count(*) from test", ()).await?;
assert_eq!(
Expand Down
10 changes: 7 additions & 3 deletions libsql-sys/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ extern "C" {
}

#[cfg(feature = "encryption")]
pub fn set_encryption_key(db: *mut libsql_ffi::sqlite3, key: &[u8]) -> i32 {
/// # Safety
/// db must point to a vaid sqlite database
pub unsafe fn set_encryption_key(db: *mut libsql_ffi::sqlite3, key: &[u8]) -> i32 {
unsafe { sqlite3_key(db, key.as_ptr() as _, key.len() as _) as i32 }
}

#[cfg(feature = "encryption")]
pub fn leak_pager(db: *mut libsql_ffi::sqlite3) -> *mut crate::ffi::Pager {
/// # Safety
/// db must point to a vaid sqlite database
pub unsafe fn leak_pager(db: *mut libsql_ffi::sqlite3) -> *mut crate::ffi::Pager {
unsafe { libsql_leak_pager(db) }
}

Expand Down Expand Up @@ -116,7 +120,7 @@ impl<W: Wal> Connection<W> {
}

Check failure on line 120 in libsql-sys/src/connection.rs

View workflow job for this annotation

GitHub Actions / Run Checks

Diff in /home/runner/work/libsql/libsql/libsql-sys/src/connection.rs
#[cfg(feature = "encryption")]
if let Some(encryption_key) = encryption_key {
if set_encryption_key(unsafe { conn.handle() }, &encryption_key)
if unsafe { set_encryption_key( conn.handle() , &encryption_key) }
!= rusqlite::ffi::SQLITE_OK
{
return Err(Error::SqliteFailure(
Expand Down
6 changes: 2 additions & 4 deletions libsql-sys/src/hrana/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,13 @@ impl Batch {
impl FromIterator<Stmt> for Batch {
fn from_iter<T: IntoIterator<Item = Stmt>>(stmts: T) -> Self {
let mut steps = Vec::new();

Check failure on line 290 in libsql-sys/src/hrana/proto.rs

View workflow job for this annotation

GitHub Actions / Run Checks

Diff in /home/runner/work/libsql/libsql/libsql-sys/src/hrana/proto.rs
let mut step = 0;
for stmt in stmts.into_iter() {
for (step, stmt) in stmts.into_iter().enumerate() {
let condition = if step > 0 {
Some(BatchCond::Ok { step: step - 1 })
Some(BatchCond::Ok { step: (step - 1) as u32 })
} else {
None
};
steps.push(BatchStep { condition, stmt });
step += 1;
}
Batch {
steps,
Expand Down
1 change: 1 addition & 0 deletions libsql-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::too_many_arguments)]
pub mod ffi {
//! C ffi for libsql.
Expand Down
2 changes: 1 addition & 1 deletion libsql/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl Database {
}

Check failure on line 446 in libsql/src/database.rs

View workflow job for this annotation

GitHub Actions / Run Checks

Diff in /home/runner/work/libsql/libsql/libsql/src/database.rs
#[cfg(feature = "encryption")]
if let Some(encryption_key) = encryption_key {
if libsql_sys::connection::set_encryption_key(conn.raw, &encryption_key)
if unsafe { libsql_sys::connection::set_encryption_key(conn.raw, encryption_key) }
!= crate::ffi::SQLITE_OK
{
return Err(crate::Error::Misuse(
Expand Down
2 changes: 1 addition & 1 deletion libsql/src/hrana/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Conn for HttpConnection<HttpSender> {
close: Some(Box::new(|| {
// make sure that Hrana connection is closed and all uncommitted changes
// are rolled back when we're about to drop the transaction
let _ = tokio::task::spawn(async move { tx.rollback().await });
drop(tokio::task::spawn(async move { tx.rollback().await }));
})),
})
}
Expand Down
22 changes: 9 additions & 13 deletions libsql/src/hrana/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,9 @@ where
None => Err(crate::Error::Misuse(
"no SQL statement provided".to_string(),
)),
Some(Err(e)) => Err(e.into()),
Some(Err(e)) => Err(e),
Some(Ok(stmt)) => {
let close_stream = match stmt.kind {
StmtKind::TxnBegin | StmtKind::TxnBeginReadOnly => false,
_ => true,
};
let close_stream = !matches!(stmt.kind, StmtKind::TxnBegin | StmtKind::TxnBeginReadOnly);
let inner = Stmt::new(stmt.stmt, want_rows);
Ok(Statement {
stream,
Expand Down Expand Up @@ -201,7 +198,7 @@ where

pub async fn next(&mut self) -> crate::Result<Option<super::Row>> {
let row = match self.cursor_step.next().await {
Some(Ok(row)) => row.into(),
Some(Ok(row)) => row,
Some(Err(e)) => return Err(crate::Error::Hrana(Box::new(e))),
None => return Ok(None),
};
Expand Down Expand Up @@ -303,7 +300,7 @@ impl RowInner for Row {
fn column_str(&self, idx: i32) -> crate::Result<&str> {
if let Some(value) = self.inner.get(idx as usize) {
if let proto::Value::Text { value } = value {
Ok(&value)
Ok(value)
} else {
Err(crate::Error::InvalidColumnType)
}
Expand Down Expand Up @@ -373,10 +370,9 @@ fn into_value2(value: proto::Value) -> crate::Value {
}

pub(crate) fn unwrap_err(batch_res: BatchResult) -> crate::Result<()> {
for maybe_err in batch_res.step_errors {
if let Some(e) = maybe_err {
return Err(crate::Error::Hrana(Box::new(HranaError::Api(e.message))));
}
}
Ok(())
batch_res.step_errors
.into_iter()
.find_map(|e| e)
.map(|e| Err(crate::Error::Hrana(Box::new(HranaError::Api(e.message)))))
.unwrap_or(Ok(()))
}
6 changes: 6 additions & 0 deletions libsql/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,12 @@ mod serde_ {
Ok(Value::Text(v))
}

Check failure on line 561 in libsql/src/value.rs

View workflow job for this annotation

GitHub Actions / Run Checks

Diff in /home/runner/work/libsql/libsql/libsql/src/value.rs

fn visit_str<E>(self, v: &str) -> std::result::Result<Self::Value, E>
where
E: de::Error, {
Ok(Value::Text(v.to_string()))
}

fn visit_some<D>(
self,
deserializer: D,
Expand Down
4 changes: 2 additions & 2 deletions libsql/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ async fn deserialize_row() {
(),
)
.await;
conn.execute("INSERT INTO users (id, name, score, data, age) VALUES (123, 'potato', 3.14, X'deadbeef', NULL)", ())
conn.execute("INSERT INTO users (id, name, score, data, age) VALUES (123, 'potato', 42.0, X'deadbeef', NULL)", ())
.await
.unwrap();

Expand All @@ -401,7 +401,7 @@ async fn deserialize_row() {
let data: Data = libsql::de::from_row(&row).unwrap();
assert_eq!(data.id, 123);
assert_eq!(data.name, "potato".to_string());
assert_eq!(data.score, 3.14);
assert_eq!(data.score, 42.0);
assert_eq!(data.data, vec![0xde, 0xad, 0xbe, 0xef]);
assert_eq!(data.age, None);
assert_eq!(data.none, None)
Expand Down

0 comments on commit 8c0ac13

Please sign in to comment.