diff --git a/integrations/compat/src/v0_50_to_v0_49.rs b/integrations/compat/src/v0_50_to_v0_49.rs index 7810d69905e..a69d22b977c 100644 --- a/integrations/compat/src/v0_50_to_v0_49.rs +++ b/integrations/compat/src/v0_50_to_v0_49.rs @@ -59,10 +59,10 @@ impl Debug for CompatAccessor { impl opendal_v0_49::raw::Access for CompatAccessor { type Reader = CompatWrapper; type Writer = CompatWrapper; - type Lister = CompatWrapper; + type Lister = CompatListWrapper; type BlockingReader = CompatWrapper; type BlockingWriter = CompatWrapper; - type BlockingLister = CompatWrapper; + type BlockingLister = CompatListWrapper; fn info(&self) -> Arc { let new_info = self.0.info().deref().clone(); @@ -131,7 +131,10 @@ impl opendal_v0_49::raw::Access for CompatAccesso .list(path, convert::raw_op_list_from(args)) .await .map_err(convert::error_into)?; - Ok((convert::raw_rp_list_into(rp), CompatWrapper(lister))) + Ok(( + convert::raw_rp_list_into(rp), + CompatListWrapper(path.to_string(), lister), + )) } async fn copy(&self, from: &str, to: &str, args: OpCopy) -> opendal_v0_49::Result { @@ -229,7 +232,10 @@ impl opendal_v0_49::raw::Access for CompatAccesso .0 .blocking_list(path, convert::raw_op_list_from(args)) .map_err(convert::error_into)?; - Ok((convert::raw_rp_list_into(rp), CompatWrapper(lister))) + Ok(( + convert::raw_rp_list_into(rp), + CompatListWrapper(path.to_string(), lister), + )) } fn blocking_copy(&self, from: &str, to: &str, args: OpCopy) -> opendal_v0_49::Result { @@ -281,16 +287,6 @@ impl opendal_v0_49::raw::oio::Write for Compa } } -impl opendal_v0_49::raw::oio::List for CompatWrapper { - async fn next(&mut self) -> opendal_v0_49::Result> { - self.0 - .next() - .await - .map(|v| v.map(convert::raw_oio_entry_into)) - .map_err(convert::error_into) - } -} - impl opendal_v0_49::raw::oio::BlockingRead for CompatWrapper { @@ -316,14 +312,50 @@ impl opendal_v0_49::raw::oio::Blockin } } +/// A wrapper to convert `List` from v0.50 to v0.49. +/// +/// The first `String` is the path of parent. We save it to check if the entry is itself. +/// In OpenDAL v0.50, lister will return itself, this behavior is different from v0.49. +struct CompatListWrapper(String, I); + +impl opendal_v0_49::raw::oio::List for CompatListWrapper { + async fn next(&mut self) -> opendal_v0_49::Result> { + loop { + let Some(de) = self + .1 + .next() + .await + .map(|v| v.map(convert::raw_oio_entry_into)) + .map_err(convert::error_into)? + else { + return Ok(None); + }; + if de.path() == self.0 { + continue; + } + return Ok(Some(de)); + } + } +} + impl opendal_v0_49::raw::oio::BlockingList - for CompatWrapper + for CompatListWrapper { fn next(&mut self) -> opendal_v0_49::Result> { - self.0 - .next() - .map(|v| v.map(convert::raw_oio_entry_into)) - .map_err(convert::error_into) + loop { + let Some(de) = self + .1 + .next() + .map(|v| v.map(convert::raw_oio_entry_into)) + .map_err(convert::error_into)? + else { + return Ok(None); + }; + if de.path() == self.0 { + continue; + } + return Ok(Some(de)); + } } }