diff --git a/services/backup/blob_client/Cargo.lock b/services/backup/blob_client/Cargo.lock --- a/services/backup/blob_client/Cargo.lock +++ b/services/backup/blob_client/Cargo.lock @@ -13,9 +13,9 @@ [[package]] name = "anyhow" -version = "1.0.62" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305" +checksum = "b9a8f622bcf6ff3df478e9deba3e03e4e04b300f8e6a139e192c05fa3490afc7" [[package]] name = "async-stream" @@ -114,6 +114,7 @@ name = "blob_client" version = "0.1.0" dependencies = [ + "anyhow", "async-stream", "cxx", "cxx-build", diff --git a/services/backup/blob_client/Cargo.toml b/services/backup/blob_client/Cargo.toml --- a/services/backup/blob_client/Cargo.toml +++ b/services/backup/blob_client/Cargo.toml @@ -13,6 +13,7 @@ prost = "0.11" tracing = "0.1" async-stream = "0.3" +anyhow = "1.0" [build-dependencies] cxx-build = "1.0" diff --git a/services/backup/blob_client/src/lib.rs b/services/backup/blob_client/src/lib.rs --- a/services/backup/blob_client/src/lib.rs +++ b/services/backup/blob_client/src/lib.rs @@ -32,7 +32,11 @@ unsafe fn get_client_initialize_cxx( holder_char: *const c_char, ) -> Result<()>; - unsafe fn get_client_blocking_read_cxx(holder_char: *const c_char) -> Result>; - unsafe fn get_client_terminate_cxx(holder_char: *const c_char) -> Result<()>; + unsafe fn get_client_blocking_read_cxx( + holder_char: *const c_char, + ) -> Result>; + unsafe fn get_client_terminate_cxx( + holder_char: *const c_char, + ) -> Result<()>; } } diff --git a/services/backup/blob_client/src/put_client.rs b/services/backup/blob_client/src/put_client.rs --- a/services/backup/blob_client/src/put_client.rs +++ b/services/backup/blob_client/src/put_client.rs @@ -133,7 +133,7 @@ Ok(maybe_response_message) => { let mut result = false; if let Some(response_message) = maybe_response_message { - // warning: this will produce an error if there's more unread + // warning: this will produce an error if there's more unread // responses than MPSC_CHANNEL_BUFFER_CAPACITY // you should then use put_client_blocking_read_cxx in order // to dequeue the responses in c++ and make room for more @@ -205,7 +205,11 @@ ); } } else { - report_error(&ERROR_MESSAGES, "no client detected in blocking read", Some("put")); + report_error( + &ERROR_MESSAGES, + "no client detected in blocking read", + Some("put"), + ); } } else { report_error(&ERROR_MESSAGES, "couldn't access client", Some("put")); @@ -252,7 +256,11 @@ ), } } else { - report_error(&ERROR_MESSAGES, "no client detected in write", Some("put")); + report_error( + &ERROR_MESSAGES, + "no client detected in write", + Some("put"), + ); } } else { report_error(&ERROR_MESSAGES, "couldn't access client", Some("put")); diff --git a/services/backup/blob_client/src/tools.rs b/services/backup/blob_client/src/tools.rs --- a/services/backup/blob_client/src/tools.rs +++ b/services/backup/blob_client/src/tools.rs @@ -41,6 +41,13 @@ } } +pub fn c_char_pointer_to_string_new( + c_char_pointer: *const c_char, +) -> anyhow::Result { + let holder_cstr: &CStr = unsafe { CStr::from_ptr(c_char_pointer) }; + Ok(holder_cstr.to_str()?.to_owned()) +} + pub fn string_to_c_char_pointer( signs: &String, ) -> Result<*const c_char, String> { @@ -50,3 +57,9 @@ Err(err) => Err(err.to_string()), } } + +pub fn string_to_c_char_pointer_new( + signs: &String, +) -> anyhow::Result<*const c_char, anyhow::Error> { + Ok(CString::new((&signs).as_bytes())?.as_ptr()) +}