Skip to content

Commit 386b8de

Browse files
refactor(core): Deprecate OpList::version and add versions instead (#5481)
Co-authored-by: Xuanwo <[email protected]>
1 parent 84e5a16 commit 386b8de

File tree

7 files changed

+72
-32
lines changed

7 files changed

+72
-32
lines changed

bindings/ruby/src/capability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ define_accessors!(Capability, {
8989
list_with_limit: bool,
9090
list_with_start_after: bool,
9191
list_with_recursive: bool,
92-
list_with_version: bool,
92+
list_with_versions: bool,
9393
presign: bool,
9494
presign_read: bool,
9595
presign_stat: bool,
@@ -137,7 +137,7 @@ pub fn include(gem_module: &RModule) -> Result<(), Error> {
137137
list_with_limit,
138138
list_with_start_after,
139139
list_with_recursive,
140-
list_with_version,
140+
list_with_versions,
141141
presign,
142142
presign_read,
143143
presign_stat,

core/src/layers/capability_check.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::sync::Arc;
3030
///
3131
/// There are two main differences between this checker with the `CorrectnessChecker`:
3232
/// 1. This checker provides additional checks for capabilities like write_with_content_type and
33-
/// list_with_version, among others. These capabilities do not affect data integrity, even if
33+
/// list_with_versions, among others. These capabilities do not affect data integrity, even if
3434
/// the underlying storage services do not support them.
3535
///
3636
/// 2. OpenDAL doesn't apply this checker by default. Users can enable this layer if they want to
@@ -131,7 +131,7 @@ impl<A: Access> LayeredAccess for CapabilityAccessor<A> {
131131

132132
async fn list(&self, path: &str, args: OpList) -> crate::Result<(RpList, Self::Lister)> {
133133
let capability = self.info.full_capability();
134-
if !capability.list_with_version && args.version() {
134+
if !capability.list_with_versions && args.versions() {
135135
return Err(new_unsupported_error(
136136
self.info.as_ref(),
137137
Operation::List,
@@ -191,7 +191,7 @@ impl<A: Access> LayeredAccess for CapabilityAccessor<A> {
191191
args: OpList,
192192
) -> crate::Result<(RpList, Self::BlockingLister)> {
193193
let capability = self.info.full_capability();
194-
if !capability.list_with_version && args.version() {
194+
if !capability.list_with_versions && args.versions() {
195195
return Err(new_unsupported_error(
196196
self.info.as_ref(),
197197
Operation::BlockingList,
@@ -289,16 +289,16 @@ mod tests {
289289
list: true,
290290
..Default::default()
291291
});
292-
let res = op.list_with("path/").version(true).await;
292+
let res = op.list_with("path/").versions(true).await;
293293
assert!(res.is_err());
294294
assert_eq!(res.unwrap_err().kind(), ErrorKind::Unsupported);
295295

296296
let op = new_test_operator(Capability {
297297
list: true,
298-
list_with_version: true,
298+
list_with_versions: true,
299299
..Default::default()
300300
});
301-
let res = op.lister_with("path/").version(true).await;
301+
let res = op.lister_with("path/").versions(true).await;
302302
assert!(res.is_ok())
303303
}
304304
}

core/src/raw/ops.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub struct OpList {
111111
/// by the underlying service
112112
///
113113
/// Default to `false`
114-
version: bool,
114+
versions: bool,
115115
}
116116

117117
impl Default for OpList {
@@ -121,7 +121,7 @@ impl Default for OpList {
121121
start_after: None,
122122
recursive: false,
123123
concurrent: 1,
124-
version: false,
124+
versions: false,
125125
}
126126
}
127127
}
@@ -184,14 +184,27 @@ impl OpList {
184184
}
185185

186186
/// Change the version of this list operation
187+
#[deprecated(since = "0.51.1", note = "use with_versions instead")]
187188
pub fn with_version(mut self, version: bool) -> Self {
188-
self.version = version;
189+
self.versions = version;
190+
self
191+
}
192+
193+
/// Change the version of this list operation
194+
pub fn with_versions(mut self, versions: bool) -> Self {
195+
self.versions = versions;
189196
self
190197
}
191198

192199
/// Get the version of this list operation
200+
#[deprecated(since = "0.51.1", note = "use versions instead")]
193201
pub fn version(&self) -> bool {
194-
self.version
202+
self.versions
203+
}
204+
205+
/// Get the version of this list operation
206+
pub fn versions(&self) -> bool {
207+
self.versions
195208
}
196209
}
197210

core/src/services/s3/backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ impl Access for S3Backend {
982982
list_with_limit: true,
983983
list_with_start_after: true,
984984
list_with_recursive: true,
985-
list_with_version: self.core.enable_versioning,
985+
list_with_versions: self.core.enable_versioning,
986986
list_has_etag: true,
987987
list_has_content_md5: true,
988988
list_has_content_length: true,
@@ -1060,7 +1060,7 @@ impl Access for S3Backend {
10601060
}
10611061

10621062
async fn list(&self, path: &str, args: OpList) -> Result<(RpList, Self::Lister)> {
1063-
let l = if args.version() {
1063+
let l = if args.versions() {
10641064
TwoWays::Two(PageLister::new(S3ObjectVersionsLister::new(
10651065
self.core.clone(),
10661066
path,

core/src/types/capability.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub struct Capability {
7676
pub stat_with_override_content_disposition: bool,
7777
/// Indicates if Content-Type header override is supported during stat operations.
7878
pub stat_with_override_content_type: bool,
79-
/// Indicates if versioned stat operations are supported.
79+
/// Indicates if versions stat operations are supported.
8080
pub stat_with_version: bool,
8181
/// Indicates whether cache control information is available in stat response
8282
pub stat_has_cache_control: bool,
@@ -113,7 +113,7 @@ pub struct Capability {
113113
pub read_with_override_content_disposition: bool,
114114
/// Indicates if Content-Type header override is supported during read operations.
115115
pub read_with_override_content_type: bool,
116-
/// Indicates if versioned read operations are supported.
116+
/// Indicates if versions read operations are supported.
117117
pub read_with_version: bool,
118118

119119
/// Indicates if the operator supports write operations.
@@ -155,7 +155,7 @@ pub struct Capability {
155155

156156
/// Indicates if delete operations are supported.
157157
pub delete: bool,
158-
/// Indicates if versioned delete operations are supported.
158+
/// Indicates if versions delete operations are supported.
159159
pub delete_with_version: bool,
160160
/// Maximum size supported for single delete operations.
161161
pub delete_max_size: Option<usize>,
@@ -174,8 +174,11 @@ pub struct Capability {
174174
pub list_with_start_after: bool,
175175
/// Indicates if recursive listing is supported.
176176
pub list_with_recursive: bool,
177-
/// Indicates if versioned listing is supported.
177+
/// Indicates if versions listing is supported.
178+
#[deprecated(since = "0.51.1", note = "use with_versions instead")]
178179
pub list_with_version: bool,
180+
/// Indicates if versions listing is supported.
181+
pub list_with_versions: bool,
179182
/// Indicates whether cache control information is available in list response
180183
pub list_has_cache_control: bool,
181184
/// Indicates whether content disposition information is available in list response

core/src/types/operator/operator_futures.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,20 @@ impl<F: Future<Output = Result<Vec<Entry>>>> FutureList<F> {
486486
/// by the underlying service
487487
///
488488
/// Default to `false`
489+
#[deprecated(since = "0.51.1", note = "use versions instead")]
489490
pub fn version(self, v: bool) -> Self {
490-
self.map(|args| args.with_version(v))
491+
self.map(|args| args.with_versions(v))
492+
}
493+
494+
/// The version is used to control whether the object versions should be returned.
495+
///
496+
/// - If `false`, list operation will not return with object versions
497+
/// - If `true`, list operation will return with object versions if object versioning is supported
498+
/// by the underlying service
499+
///
500+
/// Default to `false`
501+
pub fn versions(self, v: bool) -> Self {
502+
self.map(|args| args.with_versions(v))
491503
}
492504
}
493505

@@ -528,7 +540,19 @@ impl<F: Future<Output = Result<Lister>>> FutureLister<F> {
528540
/// by the underlying service
529541
///
530542
/// Default to `false`
543+
#[deprecated(since = "0.51.1", note = "use versions instead")]
531544
pub fn version(self, v: bool) -> Self {
532-
self.map(|args| args.with_version(v))
545+
self.map(|args| args.with_versions(v))
546+
}
547+
548+
/// The version is used to control whether the object versions should be returned.
549+
///
550+
/// - If `false`, list operation will not return with object versions
551+
/// - If `true`, list operation will return with object versions if object versioning is supported
552+
/// by the underlying service
553+
///
554+
/// Default to `false`
555+
pub fn versions(self, v: bool) -> Self {
556+
self.map(|args| args.with_versions(v))
533557
}
534558
}

core/tests/behavior/async_list.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
4747
test_list_file_with_recursive,
4848
test_list_root_with_recursive,
4949
test_remove_all,
50-
test_list_files_with_version,
51-
test_list_with_version_and_limit,
52-
test_list_with_version_and_start_after
50+
test_list_files_with_versions,
51+
test_list_with_versions_and_limit,
52+
test_list_with_versions_and_start_after
5353
))
5454
}
5555

@@ -575,8 +575,8 @@ pub async fn test_list_only(op: Operator) -> Result<()> {
575575
Ok(())
576576
}
577577

578-
pub async fn test_list_files_with_version(op: Operator) -> Result<()> {
579-
if !op.info().full_capability().list_with_version {
578+
pub async fn test_list_files_with_versions(op: Operator) -> Result<()> {
579+
if !op.info().full_capability().list_with_versions {
580580
return Ok(());
581581
}
582582

@@ -586,7 +586,7 @@ pub async fn test_list_files_with_version(op: Operator) -> Result<()> {
586586
op.write(file_path.as_str(), "1").await?;
587587
op.write(file_path.as_str(), "2").await?;
588588

589-
let mut ds = op.list_with(parent.as_str()).version(true).await?;
589+
let mut ds = op.list_with(parent.as_str()).versions(true).await?;
590590
ds.retain(|de| de.path() != parent.as_str());
591591

592592
assert_eq!(ds.len(), 2);
@@ -608,13 +608,13 @@ pub async fn test_list_files_with_version(op: Operator) -> Result<()> {
608608
}
609609

610610
// listing a directory with version, which contains more object versions than a page can take
611-
pub async fn test_list_with_version_and_limit(op: Operator) -> Result<()> {
611+
pub async fn test_list_with_versions_and_limit(op: Operator) -> Result<()> {
612612
// Gdrive think that this test is an abuse of their service and redirect us
613613
// to an infinite loop. Let's ignore this test for gdrive.
614614
if op.info().scheme() == Scheme::Gdrive {
615615
return Ok(());
616616
}
617-
if !op.info().full_capability().list_with_version {
617+
if !op.info().full_capability().list_with_versions {
618618
return Ok(());
619619
}
620620

@@ -633,7 +633,7 @@ pub async fn test_list_with_version_and_limit(op: Operator) -> Result<()> {
633633
.collect();
634634
expected.push(parent.to_string());
635635

636-
let mut objects = op.lister_with(parent).version(true).limit(5).await?;
636+
let mut objects = op.lister_with(parent).versions(true).limit(5).await?;
637637
let mut actual = vec![];
638638
while let Some(o) = objects.try_next().await? {
639639
let path = o.path().to_string();
@@ -648,8 +648,8 @@ pub async fn test_list_with_version_and_limit(op: Operator) -> Result<()> {
648648
Ok(())
649649
}
650650

651-
pub async fn test_list_with_version_and_start_after(op: Operator) -> Result<()> {
652-
if !op.info().full_capability().list_with_version {
651+
pub async fn test_list_with_versions_and_start_after(op: Operator) -> Result<()> {
652+
if !op.info().full_capability().list_with_versions {
653653
return Ok(());
654654
}
655655

@@ -672,7 +672,7 @@ pub async fn test_list_with_version_and_start_after(op: Operator) -> Result<()>
672672

673673
let mut objects = op
674674
.lister_with(dir)
675-
.version(true)
675+
.versions(true)
676676
.start_after(&given[2])
677677
.await?;
678678
let mut actual = vec![];

0 commit comments

Comments
 (0)