From f36243b7fea2e0f9117ecfda163d59490ec1bb93 Mon Sep 17 00:00:00 2001 From: Adnan Alhomssi Date: Tue, 11 Feb 2025 18:28:38 +0100 Subject: [PATCH 1/4] strip prefix from returned error paths --- src/crud_ops.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/crud_ops.rs b/src/crud_ops.rs index 85eb2ae..cf0bf70 100644 --- a/src/crud_ops.rs +++ b/src/crud_ops.rs @@ -1,4 +1,4 @@ -use crate::{duration_on_drop, encryption::{encrypt, CrypterReader, CrypterWriter, Mode}, error::Kind as ErrorKind, export_queued_op, metrics, util::{cstr_to_path, BufWriter}, with_retries, BoxedReader, BoxedUpload, CResult, Client, Context, NotifyGuard, RawConfig, RawResponse, Request, ResponseGuard, SQ}; +use crate::{duration_on_drop, encryption::{encrypt, CrypterReader, CrypterWriter, Mode}, error::Kind as ErrorKind, export_queued_op, metrics, util::{cstr_to_path, string_to_path, BufWriter}, with_retries, BoxedReader, BoxedUpload, CResult, Client, Context, NotifyGuard, RawConfig, RawResponse, Request, ResponseGuard, SQ}; use bytes::Bytes; use ::metrics::counter; @@ -230,7 +230,7 @@ impl Client { async fn bulk_delete_impl(&self, paths: &Vec) -> crate::Result> { // Add the client prefix to the provided paths if needed - let paths = paths.into_iter().map(|path| self.full_path(path)).collect::>(); + let prefixed_paths = paths.into_iter().map(|path| self.full_path(path)).collect::>(); let stream = stream::iter(paths.iter().map(|path| Ok(path.clone()))).boxed(); let results = self.store.delete_stream(stream) .collect::>().await; @@ -239,8 +239,8 @@ impl Client { let num_results = results.len(); let failures = results .into_iter() - .enumerate() - .filter_map(|(index, result)| { + .zip(prefixed_paths.into_iter()) // Stops at the shorter iterator + .filter_map(|(result, path)| { match result { Ok(_) => { None @@ -252,7 +252,17 @@ impl Client { None }, _ => { - Some((paths[index].clone(), e.into())) + match self.config.prefix.as_ref() { + None => Some((path, e.into())), + Some(prefix_str) => { + if let Some(stripped_str) = path.as_ref().strip_prefix(prefix_str) { + let truncated = unsafe { string_to_path(stripped_str.to_string()) }; + Some((truncated, e.into())) + } else { + Some((path, e.into())) + } + } + } } }, } From af0820867a38c7401d7a88787aa59c47448d17ab Mon Sep 17 00:00:00 2001 From: Adnan Alhomssi Date: Tue, 11 Feb 2025 18:29:21 +0100 Subject: [PATCH 2/4] bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08e54fe..682310d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1402,7 +1402,7 @@ dependencies = [ [[package]] name = "object_store_ffi" -version = "0.12.1" +version = "0.12.2" dependencies = [ "anyhow", "async-channel", diff --git a/Cargo.toml b/Cargo.toml index cfa5ede..a6eccbb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "object_store_ffi" -version = "0.12.1" +version = "0.12.2" edition = "2021" [[bench]] From d2e814da5edafb01960de2349cd7ba63b4fdc2bb Mon Sep 17 00:00:00 2001 From: Adnan Alhomssi Date: Tue, 11 Feb 2025 20:07:04 +0100 Subject: [PATCH 3/4] just use the original paths instead of stripping prefix --- src/crud_ops.rs | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/crud_ops.rs b/src/crud_ops.rs index cf0bf70..f12017d 100644 --- a/src/crud_ops.rs +++ b/src/crud_ops.rs @@ -228,10 +228,10 @@ impl Client { with_retries!(self, self.delete_impl(path).await) } - async fn bulk_delete_impl(&self, paths: &Vec) -> crate::Result> { + async fn bulk_delete_impl(&self, og_paths: &Vec) -> crate::Result> { // Add the client prefix to the provided paths if needed - let prefixed_paths = paths.into_iter().map(|path| self.full_path(path)).collect::>(); - let stream = stream::iter(paths.iter().map(|path| Ok(path.clone()))).boxed(); + let prefixed_paths = og_paths.into_iter().map(|path| self.full_path(path)).collect::>(); + let stream = stream::iter(prefixed_paths.iter().map(|path| Ok(path.clone()))).boxed(); let results = self.store.delete_stream(stream) .collect::>().await; // We count the number of results to raise an error if some paths were not @@ -239,8 +239,8 @@ impl Client { let num_results = results.len(); let failures = results .into_iter() - .zip(prefixed_paths.into_iter()) // Stops at the shorter iterator - .filter_map(|(result, path)| { + .zip(og_paths.into_iter()) // Stops at the shorter iterator + .filter_map(|(result, og_path)| { match result { Ok(_) => { None @@ -252,24 +252,14 @@ impl Client { None }, _ => { - match self.config.prefix.as_ref() { - None => Some((path, e.into())), - Some(prefix_str) => { - if let Some(stripped_str) = path.as_ref().strip_prefix(prefix_str) { - let truncated = unsafe { string_to_path(stripped_str.to_string()) }; - Some((truncated, e.into())) - } else { - Some((path, e.into())) - } - } - } + Some((og_path.clone(), e.into())) } }, } }).collect::>(); // Rail guard to catch generic errors - if num_results < paths.len() { + if num_results < og_paths.len() { if num_results == 0 { tracing::warn!("delete_stream returned zero results"); Err(crate::Error::invalid_response("Some paths were not deleted")) From aea51657d4aa178e3f52e5e84d99f55da7625e99 Mon Sep 17 00:00:00 2001 From: Adnan Alhomssi Date: Tue, 11 Feb 2025 20:07:54 +0100 Subject: [PATCH 4/4] clean up --- src/crud_ops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crud_ops.rs b/src/crud_ops.rs index f12017d..0f25005 100644 --- a/src/crud_ops.rs +++ b/src/crud_ops.rs @@ -1,4 +1,4 @@ -use crate::{duration_on_drop, encryption::{encrypt, CrypterReader, CrypterWriter, Mode}, error::Kind as ErrorKind, export_queued_op, metrics, util::{cstr_to_path, string_to_path, BufWriter}, with_retries, BoxedReader, BoxedUpload, CResult, Client, Context, NotifyGuard, RawConfig, RawResponse, Request, ResponseGuard, SQ}; +use crate::{duration_on_drop, encryption::{encrypt, CrypterReader, CrypterWriter, Mode}, error::Kind as ErrorKind, export_queued_op, metrics, util::{cstr_to_path, BufWriter}, with_retries, BoxedReader, BoxedUpload, CResult, Client, Context, NotifyGuard, RawConfig, RawResponse, Request, ResponseGuard, SQ}; use bytes::Bytes; use ::metrics::counter;