Skip to content

fix(mirror): preserve content type during mirror sync#61

Merged
overtrue merged 3 commits intomainfrom
codex/issue-59-mirror-content-type
Mar 20, 2026
Merged

fix(mirror): preserve content type during mirror sync#61
overtrue merged 3 commits intomainfrom
codex/issue-59-mirror-content-type

Conversation

@overtrue
Copy link
Contributor

@overtrue overtrue commented Mar 20, 2026

Related Issue

Closes #59.

Background

rc mirror copies objects between S3-compatible backends. Before this change, the mirror flow downloaded the source object bytes and uploaded them to the destination without forwarding the source Content-Type.

That meant a source object such as image/jpeg could be mirrored as application/octet-stream on the destination side. This is user-visible because browsers and downstream consumers may handle the mirrored object differently after the sync.

Root Cause

The mirror implementation used get_object followed by put_object(..., None). Even though head_object already exposed the source object's content_type through ObjectInfo, the mirror upload path did not pass that metadata into the destination upload.

Solution

This PR makes two related changes:

  • It introduces a small helper for the mirror copy path that reads source object metadata before uploading and forwards source_info.content_type into the destination put_object call.
  • It falls back to the previous byte-copy behavior if the metadata lookup fails, while logging a warning instead of turning that case into a hard failure.
  • It updates AGENTS.md to require semantic/conventional PR titles and clear PR descriptions that include issue, background, solution, and test status.

This keeps the bug fix targeted to the reported mirror behavior while also documenting the PR rules used for this contribution.

Tests

The mirror fix was validated with the following checks on commit 44efbe6:

  • cargo fmt --all
  • cargo clippy --workspace -- -D warnings
  • cargo test --workspace
  • cargo test -p rustfs-cli --features integration test_mirror_preserves_content_type

Regression coverage added in this PR includes:

  • unit tests for preserving a source image/jpeg content type during mirror copies
  • unit tests for the None content-type fallback path
  • an integration test that uploads an object with image/jpeg, mirrors it to another bucket, and verifies the destination still reports image/jpeg via stat --json

The follow-up AGENTS.md update is a markdown-only documentation change in commit 1326278, so no additional Rust checks were required under the repository rules.

Notes

This PR fixes Content-Type preservation specifically. It does not attempt to mirror other object metadata beyond what the current upload interface supports.

@overtrue overtrue changed the title [codex] Preserve Content-Type during mirror sync fix(mirror): preserve content type during mirror sync Mar 20, 2026
@overtrue overtrue marked this pull request as ready for review March 20, 2026 15:00
Copilot AI review requested due to automatic review settings March 20, 2026 15:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes rc mirror so mirrored objects preserve the source object’s Content-Type, addressing a user-visible metadata loss during sync operations.

Changes:

  • Add a mirror copy helper that attempts head_object to capture content_type and forwards it into the destination put_object.
  • Introduce small source/target traits to enable unit testing of the metadata-preserving copy behavior.
  • Add an integration test that verifies Content-Type is preserved end-to-end (cp --content-typemirrorstat --json).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
crates/cli/src/commands/mirror.rs Adds metadata-aware copy path (preserve content_type) plus unit tests around the helper.
crates/cli/tests/integration.rs Adds an integration regression test verifying mirrored objects keep content_type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@overtrue overtrue merged commit 5074890 into main Mar 20, 2026
15 checks passed
@overtrue overtrue deleted the codex/issue-59-mirror-content-type branch March 20, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mirror does not preserve Content-Type when copying objects between S3 backends

2 participants