Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

flashers: fix not overwriting mismatching hashes#383

Merged
NickCao merged 1 commit intojumpstarter-dev:mainfrom
bennyz:fix-storage-write
Mar 31, 2025
Merged

flashers: fix not overwriting mismatching hashes#383
NickCao merged 1 commit intojumpstarter-dev:mainfrom
bennyz:fix-storage-write

Conversation

@bennyz
Copy link
Copy Markdown
Member

@bennyz bennyz commented Mar 30, 2025

Currently, despite mismatch in hash, the existing file will not be over-written because the metadata matches. However, file name and sizes are likely to be the same because of automotive-image-builder defaults.

Since metadata check is unreliable, if there is a checksum mismatch overwrite the image.

Summary by CodeRabbit

  • Refactor
    • Streamlined the image transfer process to reduce redundant checks and improve efficiency.
    • Updated the metadata generation to now include a computed file hash for enhanced consistency.

@bennyz bennyz requested review from Copilot and mangelajo March 30, 2025 11:11
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 30, 2025

Walkthrough

The changes simplify the image transfer process in the _transfer_bg_thread method by consolidating multiple file existence checks into a single conditional based on computed or provided hash values. When the operator scheme is "fs", the method computes the SHA256 hash; otherwise, it uses a given known hash. A single check determines if the image exists in the storage, logging either an "already exists" message or an overwrite notification. Additionally, the metadata creation process now accepts an optional file_hash parameter, embedding the hash into the returned metadata.

Changes

File Change Summary
packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py Streamlined _transfer_bg_thread by consolidating hash checks using SHA256 or provided hash; updated _create_metadata_and_json signature to include file_hash

Sequence Diagram(s)

sequenceDiagram
    participant T as _transfer_bg_thread
    participant S as Storage
    participant M as _create_metadata_and_json

    T->>T: Check operator scheme
    alt fs scheme
        T->>T: Compute SHA256 of file
    else Non-local
        T->>T: Use provided known hash
    end
    T->>S: Compare computed/provided hash with storage hash
    alt Hashes match
        T->>T: Log "Image already exists" and skip upload
    else Hashes differ
        T->>S: Log "Overwriting image" and perform upload
    end
    T->>M: Call metadata creation (pass file_hash)
    M-->>T: Return metadata JSON with file_hash
Loading

Possibly related PRs

Suggested reviewers

  • mangelajo

Poem

I'm a bunny on the run,
Hopping through code under the sun,
Simplifying checks with a cheeky grin,
Hashes aligned, new paths begin,
Metadata updated with a joyful twitch,
Leaping with pride in every switch!
🐇💻✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 178696e and 2b7f9b3.

📒 Files selected for processing (1)
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Redirect rules - jumpstarter-docs
  • GitHub Check: Header rules - jumpstarter-docs
  • GitHub Check: Pages changed - jumpstarter-docs
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: e2e

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 30, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit 2b7f9b3
🔍 Latest deploy log https://app.netlify.com/sites/jumpstarter-docs/deploys/67eaae16213f3e0008166ff4
😎 Deploy Preview https://deploy-preview-383--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Copy Markdown

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

This PR addresses an issue where an image stored in the filesystem may not be overwritten despite a checksum mismatch by basing the check solely on metadata.

  • Removed metadata-based checks and switched to comparing actual file hashes.
  • Updated the metadata creation function to store the file hash.

Comment thread packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py (1)

291-297: Good metadata structure update

The metadata dictionary now includes the file hash, which provides better tracking and verification capabilities for stored files.

Consider adding a compact comment explaining the significance of storing the hash in metadata for future maintainers.

 metadata_dict = {
     "path": str(src_path),
     "content_length": metadata.content_length,
     "etag": metadata.etag,
+    # Store hash for verification during future operations
     "hash": file_hash,
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 955baef and 18a962d.

📒 Files selected for processing (1)
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: pytest-matrix (3.13)
🔇 Additional comments (5)
packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py (5)

241-242: Simplified docstring is more maintainable

The simplified docstring is easier to maintain while still communicating the purpose of the method. Consider adding back minimal parameter documentation to maintain clarity without the verbosity.


247-251: Good implementation of file hash handling

The code now properly handles both local files (by computing SHA256) and remote files (by using the provided hash). This approach ensures reliable hash verification regardless of the source.


253-262: Effective fix for the hash mismatch issue

This change directly addresses the PR objective by comparing file hashes instead of relying on metadata. Now files with mismatching hashes will be correctly overwritten even if metadata matches.

The logging is also helpful for debugging - it clearly indicates whether a file is being skipped or overwritten based on hash comparison.


266-268: Properly passing file hash to metadata creation

The file hash is now correctly passed to the metadata creation method, ensuring the hash is preserved with the file metadata.


288-288: Appropriate method signature update

The method signature has been properly updated to include the optional file_hash parameter with a sensible default value of None.

@bennyz bennyz force-pushed the fix-storage-write branch from 18a962d to 178696e Compare March 30, 2025 11:24
@bennyz bennyz requested a review from Copilot March 30, 2025 11:24
Copy link
Copy Markdown

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

This PR addresses an issue where images are not overwritten when checksum mismatches occur by refactoring the transfer logic and enhancing metadata generation. Key changes include:

  • Removal of redundant metadata checks and streamlining of the image transfer process.
  • Incorporation of computed file hashes in both storage verification and metadata generation.
  • Update of the _create_metadata_and_json method to accept an optional file_hash parameter.
Comments suppressed due to low confidence (1)

packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py:288

  • [nitpick] Consider updating the function docstring to include documentation for the new file_hash parameter to clearly reflect its purpose.
def _create_metadata_and_json(self, src_operator, src_path, file_hash=None) -> tuple[Metadata, str]:

Currently, despite mismatch in hash, the existing file will not be
over-written because the metadata matches. However, file name and sizes
are likely to be the same because of automotive-image-builder defaults.

Since metadata check is unreliable, if there is a checksum mismatch
overwrite the image.

Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
@bennyz bennyz force-pushed the fix-storage-write branch from 178696e to 2b7f9b3 Compare March 31, 2025 15:00
@NickCao NickCao merged commit c8b8a3a into jumpstarter-dev:main Mar 31, 2025
16 of 18 checks passed
@mangelajo mangelajo added this to the 0.6.0 milestone May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants