mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-19 02:56:18 +00:00
fix(head): clearer NoSuchKey for prefix keys and validate part numbers (#1638)
This commit is contained in:
@@ -1102,3 +1102,27 @@ pub(crate) async fn wrap_response_with_cors<T>(
|
||||
|
||||
response
|
||||
}
|
||||
|
||||
/// Parse part number from Option<i32> to Option<usize> with validation
|
||||
/// This function checks that the part number is greater than 0 and
|
||||
/// converts it to usize, returning an error if invalid
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `part_number` - The optional part number as i32
|
||||
/// * `op` - The operation name for logging purposes
|
||||
///
|
||||
/// # Returns
|
||||
/// * `Ok(Some(usize))` if part number is valid
|
||||
/// * `Ok(None)` if part number is None
|
||||
/// * `Err(S3Error)` if part number is invalid (0 or overflow)
|
||||
#[inline]
|
||||
pub(crate) fn parse_part_number_i32_to_usize(part_number: Option<i32>, op: &'static str) -> S3Result<Option<usize>> {
|
||||
match part_number {
|
||||
None => Ok(None),
|
||||
Some(n) if n <= 0 => Err(S3Error::with_message(
|
||||
S3ErrorCode::InvalidArgument,
|
||||
format!("{op}: invalid partNumber {n}, must be a positive integer"),
|
||||
)),
|
||||
Some(n) => Ok(Some(n as usize)),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user