fix(cp): avoid guessed content type for multipart uploads#203
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses failures in rc cp multipart uploads caused by forwarding an automatically guessed Content-Type (e.g., text/plain) into the multipart create request, which some RustFS multipart paths reject. The change keeps MIME guessing for small single-part uploads, while ensuring multipart-sized uploads only send an explicit --content-type when provided.
Changes:
- Move content-type selection to occur after file size is known, enabling size-based selection.
- Add
select_upload_content_typehelper to skip guessed MIME types for multipart-sized uploads while honoring explicit--content-type. - Add unit tests covering the helper’s selection behavior.
Comments suppressed due to low confidence (2)
crates/cli/src/commands/cp.rs:351
select_upload_content_typeusesfile_size > MULTIPART_THRESHOLDto decide when to skip guessed MIME types, butMULTIPART_THRESHOLDis documented as “files at least this size use multipart upload” andupload_filelogs/chooses the multipart progress bar onfile_size >= MULTIPART_THRESHOLD. This boundary mismatch means a file exactly equal to the threshold will still forward the guessed content type even though it’s treated as multipart elsewhere. Align the comparison (and ideally share the same predicate as the actual multipart decision) so the behavior is consistent at the threshold.
fn select_upload_content_type<'a>(
explicit_type: Option<&'a str>,
guessed_type: Option<&'a str>,
file_size: u64,
) -> Option<&'a str> {
if file_size > MULTIPART_THRESHOLD {
explicit_type
} else {
explicit_type.or(guessed_type)
}
crates/cli/src/commands/cp.rs:895
- The new unit tests cover
< thresholdand> threshold, but don’t assert behavior forfile_size == MULTIPART_THRESHOLD, which is currently ambiguous/inconsistent with the constant’s doc comment and the progress-bar condition. Add a boundary test for the exact-threshold size once the intended semantics (>=vs>) are clarified so regressions at the cutoff are caught.
#[test]
fn test_select_upload_content_type_uses_guess_for_small_files() {
let selected =
select_upload_content_type(None, Some("text/plain"), MULTIPART_THRESHOLD - 1);
assert_eq!(selected, Some("text/plain"));
}
#[test]
fn test_select_upload_content_type_skips_guess_for_multipart_files() {
let selected =
select_upload_content_type(None, Some("text/plain"), MULTIPART_THRESHOLD + 1);
assert_eq!(selected, None);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
92041ee to
fa61632
Compare
fa61632 to
c44a04d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue
Closes #191
Background
Large local-to-remote
rc cpuploads use multipart upload. For files such as a generated.txtfile, the CLI guessedtext/plainfrom the extension and forwarded that value into the multipart create request. Some RustFS multipart create paths reject that inferred content type, while small single-part uploads still work.Solution
Skip automatically guessed content types for multipart-sized uploads. Explicit
--content-typevalues are still honored, and small single-part uploads keep the existing MIME guessing behavior.Tests
cargo fmt --all --checkcargo test -p rustfs-cli commands::cp::tests::test_select_upload_content_type --libcargo clippy --workspace -- -D warningscargo test --workspace