Skip to content

Commit 2c6f943

Browse files
committed
code review updates
1 parent f11fafd commit 2c6f943

File tree

7 files changed

+34
-18
lines changed

7 files changed

+34
-18
lines changed

.claude/settings.local.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
2+
"$schema": "https://json.schemastore.org/claude-code-settings.json",
23
"permissions": {
34
"allow": [
4-
"Bash(grep:*)"
5+
"Bash(grep:*)",
6+
"WebSearch",
7+
"Bash(cargo check:*)",
8+
"Bash(cargo test:*)",
9+
"Bash(find:*)"
510
],
611
"deny": []
7-
},
8-
"$schema": "https://json.schemastore.org/claude-code-settings.json"
12+
}
913
}

benches/s3/bench_object_retention.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(crate) async fn bench_put_object_retention(criterion: &mut Criterion) {
3434
.client(ctx.client.clone())
3535
.bucket(ctx.bucket.clone())
3636
.object(ctx.object.clone())
37-
.retention_mode(Some(RetentionMode::GOVERNANCE))
37+
.retention_mode(RetentionMode::GOVERNANCE)
3838
.retain_until_date(Some(utc_now() + chrono::Duration::days(1)))
3939
.build()
4040
},
@@ -53,7 +53,7 @@ pub(crate) async fn bench_get_object_retention(criterion: &mut Criterion) {
5353
.client(ctx.client.clone())
5454
.bucket(ctx.bucket.clone())
5555
.object(ctx.object.clone())
56-
.retention_mode(Some(RetentionMode::GOVERNANCE))
56+
.retention_mode(RetentionMode::GOVERNANCE)
5757
.retain_until_date(Some(utc_now() + chrono::Duration::days(1)))
5858
.build()
5959
.send()

src/s3/builders/append_object.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,10 @@ impl AppendObjectContent {
231231
data: Arc::new(seg_bytes),
232232
};
233233
ao.send().await
234-
} else if object_size.is_known() && (seg_bytes.len() as u64) < part_size {
234+
} else if let Some(expected) = object_size.value()
235+
&& (seg_bytes.len() as u64) < part_size
236+
{
235237
// Not enough data!
236-
let expected = object_size.as_u64().unwrap();
237238
let got = seg_bytes.len() as u64;
238239
Err(ValidationErr::InsufficientData { expected, got })?
239240
} else {

src/s3/builders/put_object.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ pub struct PutObjectContent {
450450
retention: Option<Retention>,
451451
#[builder(default = false)]
452452
legal_hold: bool,
453-
#[builder(default)]
453+
#[builder(default, setter(into))]
454454
part_size: Size,
455455
#[builder(default, setter(into))]
456456
content_type: Option<String>,
@@ -548,9 +548,10 @@ impl PutObjectContent {
548548
.await?;
549549

550550
Ok(PutObjectContentResponse::new(resp, size))
551-
} else if object_size.is_known() && (seg_bytes.len() as u64) < part_size {
551+
} else if let Some(expected) = object_size.value()
552+
&& (seg_bytes.len() as u64) < part_size
553+
{
552554
// Not enough data!
553-
let expected: u64 = object_size.as_u64().unwrap();
554555
let got: u64 = seg_bytes.len() as u64;
555556
Err(ValidationErr::InsufficientData { expected, got }.into())
556557
} else {
@@ -642,8 +643,7 @@ impl PutObjectContent {
642643
return Err(ValidationErr::TooManyParts(part_number as u64).into());
643644
}
644645

645-
if object_size.is_known() {
646-
let exp = object_size.as_u64().unwrap();
646+
if let Some(exp) = object_size.value() {
647647
if exp < total_read {
648648
return Err(ValidationErr::TooMuchData(exp).into());
649649
}
@@ -686,8 +686,7 @@ impl PutObjectContent {
686686
// Complete the multipart upload.
687687
let size = parts.iter().map(|p| p.size).sum();
688688

689-
if object_size.is_known() {
690-
let expected = object_size.as_u64().unwrap();
689+
if let Some(expected) = object_size.value() {
691690
if expected != size {
692691
return Err(ValidationErr::InsufficientData {
693692
expected,

src/s3/client/put_object_retention.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ impl MinioClient {
2424
///
2525
/// 🛈 This operation is not supported for express buckets.
2626
///
27+
/// Note: there is no separate delete object retention API. To remove object retention, you must
28+
/// call put_object_retention without '.retention_mode()' or '.retain_until_date()' to remove the retention.
29+
/// You must set '.bypass_governance_mode(true)' to remove retention from objects in GOVERNANCE mode.
30+
///
2731
/// # Example
2832
///
2933
/// ```no_run
@@ -40,7 +44,7 @@ impl MinioClient {
4044
/// let retain_until_date = utc_now() + chrono::Duration::days(1);
4145
/// let resp: PutObjectRetentionResponse = client
4246
/// .put_object_retention("bucket-name", "object-name")
43-
/// .retention_mode(Some(RetentionMode::GOVERNANCE))
47+
/// .retention_mode(RetentionMode::GOVERNANCE)
4448
/// .retain_until_date(Some(retain_until_date))
4549
/// .build().send().await.unwrap();
4650
/// println!("set the object retention for object '{}'", resp.object());

src/s3/object_content.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ pub enum Size {
3636
}
3737

3838
impl Size {
39+
/// Returns `true` if the size is known and `false` otherwise.
3940
pub fn is_known(&self) -> bool {
4041
matches!(self, Size::Known(_))
4142
}
4243

44+
/// Returns `true` if the size is unknown and `false` otherwise.
4345
pub fn is_unknown(&self) -> bool {
4446
matches!(self, Size::Unknown)
4547
}
4648

47-
pub fn as_u64(&self) -> Option<u64> {
49+
/// Returns the size if known, otherwise returns `None`.
50+
pub fn value(&self) -> Option<u64> {
4851
match self {
4952
Size::Known(v) => Some(*v),
5053
Size::Unknown => None,
@@ -61,6 +64,12 @@ impl From<Option<u64>> for Size {
6164
}
6265
}
6366

67+
impl From<u64> for Size {
68+
fn from(value: u64) -> Self {
69+
Size::Known(value)
70+
}
71+
}
72+
6473
#[cfg(test)]
6574
impl Arbitrary for Size {
6675
fn arbitrary(g: &mut quickcheck::Gen) -> Self {

tests/test_object_put.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// limitations under the License.
1515

1616
use http::header;
17-
use minio::s3::builders::Size::Known;
1817
use minio::s3::builders::{MIN_PART_SIZE, ObjectContent};
1918
use minio::s3::response::a_response_traits::{
2019
HasBucket, HasEtagFromHeaders, HasIsDeleteMarker, HasObject, HasS3Fields,
@@ -164,7 +163,7 @@ async fn put_object_content_2(ctx: TestContext, bucket_name: String) {
164163
&object_name,
165164
ObjectContent::new_from_stream(data_src, None),
166165
)
167-
.part_size(Known(MIN_PART_SIZE))
166+
.part_size(MIN_PART_SIZE)
168167
.build()
169168
.send()
170169
.await

0 commit comments

Comments
 (0)